+ Reply to Thread
Results 1 to 13 of 13

Color specific lines green

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Color specific lines green

    I create, copy, and use a lot of macro routines, mainly in Excel. Often I want to pass these on to others, so I try to comment all the macros, the copy them to Word documents with explantory text before and after the macro. When I do this, I'd like to be able to have all of my comment lines within the macros come out in green. Since every comment line begins with an apostrophe, it seems like it would be simple to have a Word macro that colors all lines beginning with an apostrophe green, but I don't know how to do it. I'd appreciate some help.

    Thanks,
    John
    Last edited by jomili; 01-25-2012 at 06:37 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Color specific lines green

    jomili,

    Word macro that will detect an apostrophe and color the text green:
    Please Login or Register  to view this content.
    Last edited by tigeravatar; 01-25-2012 at 06:25 PM.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Color specific lines green

    Tigeravatar,

    Thanks for your help. It appears to work on my samples, but looking at the code it seems it would color the whole paragraph green. Since I just want the macro comment lines to be colored, would there be a case where Word would look at multiple lines of macro code as all being in the same paragraph? Would we want to change it to look at the line instead of the paragraph?

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Color specific lines green

    In the visual basic editor, the only way to go from a comment line to the next code line is to use the Return key. Word sees that as a new paragraph, so there should never be any overlap. Let me know if you do find any examples where it doesn't work as intended though.

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Color specific lines green

    Thanks for the explanation. I'll look for it, and if I spot any I'll let you know. Thanks so much for your help.

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Color specific lines green

    Tigeravatar,

    I have a case where the macro doesn't appear to be working. I've attached my example. What needs to be done to make it work?

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Color specific lines green

    I ran the macro on that doc and only the comment lines were set to green text. How is it not working?

  8. #8
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Color specific lines green

    Sorry, I should have given more details. Here's what's happening;

    I put the macro in Normal, in Module 1.

    I open the Word document, go to Tools>Macro>Macros>then click on the macro and hit Run. Nothing happens on this document. I added a line to the macro:
    Please Login or Register  to view this content.
    When I rerun the macro, the message box pops up, but no change happens on the document.

    Do I need to put the macro directly into each document? I was thinking Normal worked kind of like the PERSONAL.xls, where I'm used to storing my macros.

    I've attached another example. In this one, the macro works on the line beginning with " 'Makes every number " but doesn't work on the line beginning with " 'Remove Subtotals " or any of the lines further down. Visually, it appears that the apostrophe differs from the first one, but I don't know how to determine that for sure. A lot of these are copied from the web and pasted into Word, so maybe I've got a different character than an apostrophe in some. If that's the case, can we adapt this to handle the different variations?

    Thanks for your help on this.

    John
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Color specific lines green

    TigerAvatar,

    Please forgive me; my mother gave birth to an idiot.

    Apparently I never closed out Word and saved my Normal. After my last post I shut down Word and got onto other business, then reopened Word for another task and tried the macro again, and it wasn't there! I figured out what I'd done and replaced the macro, saved, shut down Word, reopened, and now it appears to be working like a charm. Sorry to get you alarmed. Thanks for all your help!

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Color specific lines green

    No worries, and anytime

  11. #11
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Color specific lines green

    TigerAvatar,

    I've got one more condition I'd like to overcome. I've attached the document to this post. The macro works fine, but when it gets to the code below it doesn't color the comments green. I know this isn't a condition I originally mentioned, but is there a way to capture these types of comments as well?
    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Color specific lines green

    jomili,

    Give this a try. If there is an apostrophe in the line, everything from the first apostrophe to the end of the line is colored green:
    Please Login or Register  to view this content.

  13. #13
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Color specific lines green

    Sweet! Exactly what was needed. Thank you so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1