vba write to word document underlined and bold


I am trying to write a vba script in Excel 2007 and the objective is to open an existing word 2007 document and write a date into the Bookmark with the font bold and underlined.

I have managed to open the word document and write the date value into the Bookmark, but i can't seem to make the font bold or underlined.

The following is my code:

    Set wordapp = New Word.Application  
    Set myDoc = wordapp.Documents.Open("C:\Template.doc")
    ' Write into word Bookmark
    If myDoc.Bookmarks.Exists("CurrentMonth") Then
        'how to make font Bold and underlined???
        myDoc.Bookmarks("CurrentMonth").Range.Text = Format(dEndMth, "d MMMM yyyy")

    End If
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try

With myDoc.Bookmarks("CurrentMonth").Range
    .Text = Format(dEndMth, "d MMMM yyyy")
    .Font.Bold = True
    .Font.UnderlineColor = wdColorAutomatic
    .Font.Underline = wdUnderlineSingle
End With

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
csharp_learnerAuthor Commented:
Thanks for the prompt reply.

This code is before, after or to replace the If statement?
csharp_learnerAuthor Commented:
Replace the code with my if statement and it worked.

Thanks for the prompt solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.