Consulting

Results 1 to 2 of 2

Thread: Setting the colour, of the text within a 'set' of bookmarks, to white

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Mar 2020
    Location
    Bendigo
    Posts
    1
    Location

    Question Setting the colour, of the text within a 'set' of bookmarks, to white

    Quote Originally Posted by macropod View Post
    Set bmClassification = ActiveDocument.Bookmarks("Classification").Range 
    bmClassification.Text = "CONFIDENTIAL" 
    bmClassification.Font.Color = RGB(237, 28, 36)
    ActiveDocument.Bookmarks.Add "Classification", bmClassification
    from a post of 31 October 2017: http://www.vbaexpress.com/forum/show...ookmark-in-VBA

    I started a new thread, though I quote from an old one, because I felt that my query, though drawing on the previous, would have been an inappropriate hijacking of the original post.

    Dear Paul

    I am quite experienced in Excel VBA (High Intermediate C+/B-) but am just beginning my Word VBA journey.

    The above code would appear to suit my requirement but I just had a few clarification requests, please.

    1. Where would one place this code - in a Subroutine or a Function and where in the code storage places - is it in a Microsoft Word Object, against the document file, or in a module stored within the Word equivalent of an XLAM, whatever file type that may be (I don't know what that file type would be, please tell me)?
    2. In respect of the
    .Range
    part of the
    ActiveDocument
    statement - what is this? I recognise this from Excel VBA where one might write, as a range,
    Range("A1:B99")
    , for example, but how does one select, or refer to, a Range in Word - is there a list of key words or what?
    3. How does one invoke this code, is it F5? Can I set up a 'situation' where the macro is run every time I open the file, if so, how do I do that, please? If I do set up a file opening invocation, may I still run the macro while editing the file, again would that be using F5 or how, please?
    4. My hopes for this adoption / adaptation of your code is that I can, by using it, set the colour, of some blocks of text (specifically, for the text of multiple document areas, which are each marked by a bookmark), to white.
    5. To be very specific, I have a lot of similarly named bookmarks, e.g. Set_Family_Number_1, Set_Family_Number_2 ... Set_Family_Number_93, can I, where you have
    Bookmarks("Classification")
    have instead
    Bookmarks("Bookmark_Name")
    , where Bookmark_Name is a text field that is setup within a normal FOR NEXT loop using a sequence of statements such as -

    DIM Bookmark_Name as String
    
    DIM I as Long
    
    DIM jbFamily_Grp as Bookmark
    
    FOR I = 1 to 93
    
    Bookmark_Name = "Set_Family_Number_" & I
    
    Set jbFamily_Grp = ActiveDocument.Bookmarks(Bookmark_Name).Range 
    jbFamily_Grp.Font.Color = RGB(255, 255, 255)
    ActiveDocument.Bookmarks.Add Bookmark_Name, jbFamily_Grp
    
    NEXT I
    I always like to use Option Explicit when I do my Excel VBA so that is why I have set out the above using all the DIM statements, which I think will be required.

    With thanks in anticipation.
    Last edited by macropod; 03-19-2020 at 02:27 PM. Reason: Added link to original thread
    Philip Hunt BScHons (LibTech) {retired}
    Flora Hill, Bendigo,
    Victoria, Australia
    philip.hunt.3152 (Facebook)

Tags for this Thread

Posting Permissions

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