Anyone knows how to post colored VBA code?

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
4,947
Office Version
  1. 365
Platform
  1. Windows
Anyone knows how to post colored VBA code like this:
I saw it in a post here:
https://www.mrexcel.com/forum/excel...ic-other-specific-characters.html#post4873793

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_Change([COLOR=darkblue]ByVal[/COLOR] Target [COLOR=darkblue]As[/COLOR] Range)
  [COLOR=darkblue]Dim[/COLOR] Changed [COLOR=darkblue]As[/COLOR] Range, cel [COLOR=darkblue]As[/COLOR] Range
  [COLOR=darkblue]Dim[/COLOR] s [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], sErrors [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]

  [COLOR=darkblue]Const[/COLOR] myTarget [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR] = "C1:C100"    [COLOR=green]'<- Change to suit[/COLOR][INDENT][COLOR=darkblue]Set[/COLOR] Changed = Intersect(Range(myTarget), Target)
  [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]Not[/COLOR] Changed [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
    Application.EnableEvents = [COLOR=darkblue]False[/COLOR]
    [COLOR=darkblue]With[/COLOR] CreateObject("VBScript.RegExp")
[/INDENT]
 
I guess I do as it was my post you have linked to. :)

Install the VBHTMLMaker Add-In (link in second last line of my signature block below)
Use one of the BB code options in that Add-In
In your post, paste the code in Code Tags and remove the 'Face' HTML tags from the start & end of the code.

I've moved your question as it is best here, though you may still need to use the Test Here forum to test the suggestion above.
 
Last edited:
I guess I do as it was my post you have linked to. :)

Install the VBHTMLMaker Add-In (link in second last line of my signature block below)
Use one of the BB code options in that Add-In
In your post, paste the code in Code Tags and remove the 'Face' HTML tags from the start & end of the code.

I've moved your question as it is best here, though you may still need to use the Test Here forum to test the suggestion above.


Hi, Peter thanks for the info.
Actually I don’t see any signature block in your post, but I googled ‘VBHTMLMaker’ & found it here:
Ask Mr. Excel - VBA HTML Maker
I played with it for a while, and here's one example:

Code:
[COLOR=darkblue]Sub[/COLOR] dTest100()
[COLOR=green]'test bbcode color[/COLOR]
[COLOR=darkblue]Dim[/COLOR] r [COLOR=darkblue]As[/COLOR] Range
[COLOR=darkblue]Dim[/COLOR] str1 [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], str2 [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
[COLOR=darkblue]Dim[/COLOR] i [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], j [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], k [COLOR=darkblue]As[/COLOR] Long

[COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] r [COLOR=darkblue]In[/COLOR] Range("A1:A4")
Application.FindFormat.Font.Superscript = [COLOR=darkblue]True[/COLOR]
r.Replace What:="*", Replacement:="GG", LookAt:=xlPart, _
         SearchFormat:=True, ReplaceFormat:=[COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]Next[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Thank you so much.
Regards
 
Actually I don’t see any signature block in your post,..
You don't see a line right across every one of my posts a bit up from the bottom and then below that the following?

Hope this helps, good luck.
Peter

Excel 2016 ... etc




In any case it looks like you have Got the VBHTMLMaker going. :)
 
Hi, Peter
I just realize why I can’t see any signature block, it’s because In Thread Display Options I uncheck Show Signatures. It’s fine now.
Anyway, I came up with an idea: using Notepad ++ (freeware text editor) to get colored vba code. Then I wrote a Word VBA macro to make the colored code having a BBCode tag, so I can post it to the Forum.
Here is one example:

Code:
[COLOR=blue]Sub[/COLOR] listingFile[B]()[/B]
[COLOR=blue]Dim[/COLOR] objFSO [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR]
[COLOR=blue]Dim[/COLOR] objFolder [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR]
[COLOR=blue]Dim[/COLOR] objFile [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR]
[COLOR=blue]Dim[/COLOR] i [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR][B],[/B] j [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR][B],[/B] rr [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR]
[COLOR=blue]Dim[/COLOR] va
 
Application.ScreenUpdating [B]=[/B] [COLOR=blue]False[/COLOR]
    [COLOR=blue]ReDim[/COLOR] va[B]([/B][B][COLOR=crimson]1[/COLOR][/B] [COLOR=blue]To[/COLOR] [B][COLOR=crimson]5000[/COLOR][/B][B],[/B] [B][COLOR=crimson]1[/COLOR][/B] [COLOR=blue]To[/COLOR] [B][COLOR=crimson]2[/COLOR][/B][B])[/B] [I][COLOR=seagreen]''5000 is the possible max number of file in the directory, you may change that.[/COLOR][/I]
    Range[B]([/B][COLOR=brown]"A4"[/COLOR][B])[/B] [B]=[/B] [COLOR=brown]"File List"[/COLOR]
    rr [B]=[/B] Range[B]([/B][COLOR=brown]"A:A"[/COLOR][B]).[/B]Find[B]([/B][COLOR=brown]"*"[/COLOR][B],[/B] SearchOrder[B]:=[/B]xlByRows[B],[/B] SearchDirection[B]:=[/B]xlPrevious[B]).[/B]row
    [I][COLOR=seagreen]'clear previous list[/COLOR][/I]
    [COLOR=blue]If[/COLOR] rr [B]>[/B] [B][COLOR=crimson]4[/COLOR][/B] [COLOR=blue]Then[/COLOR] Range[B]([/B]Cells[B]([/B][B][COLOR=crimson]5[/COLOR][/B][B],[/B] [COLOR=brown]"A"[/COLOR][B]),[/B] Cells[B]([/B]rr[B],[/B] [COLOR=brown]"A"[/COLOR][B])).[/B]EntireRow.Delete
 
    [I][COLOR=seagreen]'Create an instance of the FileSystemObject[/COLOR][/I]
    [COLOR=blue]Set[/COLOR] objFSO [B]=[/B] CreateObject[B]([/B][COLOR=brown]"Scripting.FileSystemObject"[/COLOR][B])[/B]
    [I][COLOR=seagreen]'Get the folder object[/COLOR][/I]
    [COLOR=blue]Set[/COLOR] objFolder [B]=[/B] objFSO.getFolder[B]([/B][COLOR=brown]"D:\zz\New Folder"[/COLOR][B])[/B] [I][COLOR=seagreen]'change this[/COLOR][/I]
    i [B]=[/B] [B][COLOR=crimson]1[/COLOR][/B]
 
    [I][COLOR=seagreen]'loops through each file in the directory and populate their names and path[/COLOR][/I]
    [COLOR=blue]For[/COLOR] [COLOR=blue]Each[/COLOR] objFile [COLOR=blue]In[/COLOR] objFolder.Files
        va[B]([/B]i[B],[/B] [B][COLOR=crimson]1[/COLOR][/B][B])[/B] [B]=[/B] objFile.name
        va[B]([/B]i[B],[/B] [B][COLOR=crimson]2[/COLOR][/B][B])[/B] [B]=[/B] objFile.path
        i [B]=[/B] i [B]+[/B] [B][COLOR=crimson]1[/COLOR][/B]
    [COLOR=blue]Next[/COLOR] objFile
 
    [I][COLOR=seagreen]'put the result starting from A5[/COLOR][/I]
    [COLOR=blue]For[/COLOR] j [B]=[/B] [B][COLOR=crimson]1[/COLOR][/B] [COLOR=blue]To[/COLOR] i [B]-[/B] [B][COLOR=crimson]1[/COLOR][/B]
        ActiveSheet.Hyperlinks.Add Anchor[B]:=[/B]Cells[B]([/B]j [B]+[/B] [B][COLOR=crimson]4[/COLOR][/B][B],[/B] [COLOR=brown]"A"[/COLOR][B]),[/B] _
        Address[B]:=[/B]va[B]([/B]j[B],[/B] [B][COLOR=crimson]2[/COLOR][/B][B]),[/B] TextToDisplay[B]:=[/B]va[B]([/B]j[B],[/B] [B][COLOR=crimson]1[/COLOR][/B][B])[/B]
    [COLOR=blue]Next[/COLOR]
 
Application.ScreenUpdating [B]=[/B] [COLOR=blue]True[/COLOR]
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]

If you or anyone else here is interested I can post the macro here.
 
Hi, Peter
I just realize why I can’t see any signature block, it’s because In Thread Display Options I uncheck Show Signatures.
Ah, I'd forgotten that there even was a setting for that. :eek:



Anyway, I came up with an idea: using Notepad ++ (freeware text editor) to get colored vba code. Then I wrote a Word VBA macro to make the colored code having a BBCode tag, so I can post it to the Forum.
Isn't that more complicated than using the VBHTML Maker?
 
Isn't that more complicated than using the VBHTML Maker?

Yes, it needs few extra steps to get the job done, but it has more color (4 color), and I can choose the output color to my liking.
Cheers
 

Forum statistics

Threads
1,214,527
Messages
6,120,057
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top