Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

Posting formatted code in the blogs and forums

Latest post Tue, Jan 22 2008 5:55 PM by Admin. 0 replies.
  • Tue, Jan 22 2008 5:55 PM

    • Admin
    • Top 25 Contributor
    • Joined on Sun, Dec 23 2007
    • Posts 72
    • Points 292

    Idea [I] Posting formatted code in the blogs and forums

    Locked |Contact
    I have been testing several solutions for posting formatted code to these forums and blogs. There are a few that I can build-in, but I am nervous messing with the code base as we are just getting going.
     
    The code below is formatted using Windows Live Writer, a free blogging tool from here. I have added to that an add-in, (there are dozens of them) to insert code snippets. (There are lots of these too).
     
    You can just add this as a plug-in very simply and it appears as a link in the right sidebar of WLW. Click on it, paste your VBA code (or other code if you need) and, in VBA's case select VB as the language.
     
    You can either set it to be in a container or post the styles with the post.
     
    Now the tricks. If you are posting to a blog (even one on www.excelusergroup.org), then you can very easily link to your account there and just post at the click of a button...job done.
     
    If you want the formatted code in a forum post, just go to View>HTML Code and copy the post in it's entirety. Now take this HTML to the forum and either start a new post or reply to an existing one and click on the HTML button in the editor and paste the code.
     
    Job done, (an example is below, posted in it's 'container', formatted, indented the lot and you can even add line numbers to make navigation or instructions for readers easier)
     
    Hope you use it
     
    Sub TestPost()
    Dim wb As Workbook
    Dim wks As Worksheet
    Dim myCell As Range
    'Assign Object Variables
    Set wb = ThisWorkbook
    Set wks = wb.ActiveSheet
    
    'Iterate range
    For Each myCell In wks.Range("A1:A100")
        If myCell.Value = 1 Then
            myCell.Value = "Do This"
        End If
    Next myCell
    
    'Release object pointers
    Set wks = Nothing
    Set wb = Nothing
    End Sub
    Filed under: , ,
    • Post Points: 0
Page 1 of 1 (1 items) | RSS
Copyright Excel User Group and the relevant contributors, 2010. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.