Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    selecing a word & setting font (WORD 2000 onwards)

    Our normal font is Verdana for our template. What I need to do is provide a way for the user to set the font to 'Courier New' by way of a keyboard shortcut (presumeably will need a macro for that) for the current word. Therefore, the macro needs to select the current word and set its font to 'Courier New' How do I do this please? Also, is this the best of providing the solution.

    Thanks in advance.

    Robie.
    Thanks.
    Robie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: selecing a word & setting font (WORD 2000 onwards)

    Create a macro in Normal.dot or in a global template (add-in):

    Sub SetCourier()
    On Error GoTo ExitHandler
    With Selection
    ' Select entire word
    .Expand Unit:=wdWord
    ' Set font
    .Font.Name = "Courier New"
    ' Optional: set font size
    ' .Font.Size = 10
    End With
    ExitHandler:
    End Sub

    Assign this macro to a keyboard shortcut (Tools | Customize... > Keyboard...)

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: selecing a word & setting font (WORD 2000 onwards)

    Thanks Hans.

    Works like a charm. Fantastico. Man you are good and fast.

    TVM.
    Thanks.
    Robie

  4. #4
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: selecing a word & setting font (WORD 2000 onwards)

    Sorry Hans, I jumped a gun bit; you are still very good and fast :0).

    Your macro can't handle the following:

    1. '$ABCD/runtime/sod/A' (need to set the whole thing as courier - the macro only does a a single word out of it)
    2. CRON_CHECKPOINTTIME (same as above; it only sets the one word wherever the cursor is at)

    Can the above be done at all?

    Thanks.

    Robie.
    Thanks.
    Robie

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: selecing a word & setting font (WORD 2000 onwards)

    Word treats character such as / and _ as word delimiters, just like a space, comma, paragraph mark etc.

    Here is a variant that only looks at spaces, tabs and returns as word delimiters:
    <code>
    Sub SetCourier()
    Dim strDelim As String
    On Error GoTo ExitHandler
    ' Delimiters
    strDelim = " " & vbCr & vbTab
    With Selection
    ' Select whole word
    .MoveStartUntil strDelim, wdBackward
    .MoveEndUntil strDelim, wdForward
    ' Set font
    .Font.Name = "Courier New"
    ' Optional: set font size
    ' .Font.Size = 10
    End With
    ExitHandler:
    End Sub
    </code>
    You can add other delimiters as needed, e.g. to include period and comma:
    <code>
    strDelim = " .," & vbCr & vbTab</code>

  6. #6
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: selecing a word & setting font (WORD 2000 onwards)

    That works just great. Wow. Thanks.

    I added the ' & . as delimters.

    Great stuff Hans - it's easy when you know how :0).
    Thanks.
    Robie

Posting Permissions

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