?
Solved

Formatting a Word 2003 footnote using VBA

Posted on 2009-02-13
6
Medium Priority
?
1,238 Views
Last Modified: 2012-06-27
I have inserted a footnote using VBA, but the text of the reference (the footnoote itself) needs to be formatted, with part of it in italics. How do I do this?

I have a footnote object from adding the footnote, viz

Set oFootnote = oDoc.Footnotes.Add(Range:=Selection.Range, Text:="Some text")
0
Comment
Question by:crescendo
  • 4
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
Antagony1960 earned 2000 total points
ID: 23633934
Try something like this:
Dim oFootNote As Object
Dim rng As Range
    Set oFootNote = ActiveDocument.Footnotes.Add(Range:=Selection.Range)
    Set rng = oFootNote.Range
    With rng
        'Make the first word bold'
        .Collapse wdCollapseEnd
        .InsertAfter "Some "
        .Font.Bold = True
        
        'Make the second word italic but not bold'
        .Collapse wdCollapseEnd
        .InsertAfter "text"
        .Font.Bold = False
        .Font.Italic = True
    End With
    Set rng = Nothing
    Set oFootNote = Nothing

Open in new window

0
 
LVL 9

Author Comment

by:crescendo
ID: 23634135
That's really good yet again. One last detail: the cursor is left in the footnote, how can I get it back to the original insertion point just before the footnote was added?
0
 
LVL 11

Expert Comment

by:Antagony1960
ID: 23634137
Thinking about it, you could do away with the oFootNote variable and just use the range object by changing line 3 to this:

    Set rng = ActiveDocument.Footnotes.Add(Selection.Range).Range
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

by:Antagony1960
ID: 23634354
Ah, we cross-posted there. :-)

Yes, we need to insert a temporary bookmark and return to that. Try this:
Dim rng As Range, bmk As Bookmark
    Set bmk = Selection.Bookmarks.Add("Temp")
    Set rng = ActiveDocument.Footnotes.Add(Selection.Range).Range
    With rng
        'Make the first word bold'
        .Collapse wdCollapseEnd
        .InsertAfter "Some "
        .Font.Bold = True
        
        'Make the second word italic but not bold'
        .Collapse wdCollapseEnd
        .InsertAfter "text"
        .Font.Bold = False
        .Font.Italic = True
    End With
    Selection.GoTo wdGoToBookmark, , , "Temp"
    Selection.Bookmarks("Temp").Delete
    Set rng = Nothing
    Set bmk = Nothing

Open in new window

0
 
LVL 9

Author Closing Comment

by:crescendo
ID: 31546561
An excellent answer, great detail.
0
 
LVL 11

Expert Comment

by:Antagony1960
ID: 23634418
Glad to have helped. :-)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question