Set Bookmark Range results in Type Mismatch

  • Thread starter Thread starter Stephen Jackson
  • Start date Start date
S

Stephen Jackson

I'm writing a VBA program which copies information from Excel into bookmarks in Word. I originally wrote it to be run from the Word document, but it makes more sense to have it in Excel so I'm migrating it over.

The original code worked, and used ActiveDocument throughout, which I've replaced with myDoc.

However, when run it gives the Type Mismatch error when I try to set the bookmark range and I can't figure out why.


myDoc is defined and works well in other places (for instance, if you add the line:

msgbox myDoc.Bookmarks(BookmarkToUse)

into this sub it correctly returns to bookmark name.

The code for the sub is:

Private Sub UpdateBookmark(BookmarkToUse As String, TextToUse As String, FontToUse As String, SizeToUse As String)

Dim BMRange As Range
BMRange.SetRange = myDoc.Bookmarks(BookmarkToUse).Range
BMRange.Text = TextToUse
BMRange.Font.Name = FontToUse
BMRange.Font.Size = SizeToUse
myDoc.Bookmarks.Add BookmarkToUse, BMRange
End Sub

Any help would be much appreciated.





Submitted via EggHeadCafe - Software Developer Portal of Choice
IIS - Create App Pools, Virtual Directories and Web Sites C# .NET
http://www.eggheadcafe.com/tutorial...476-ff05b085d86e/iis--create-app-pools-v.aspx
 
Excel has its own Range object.
MSWord has its own Range object.

I'd try:
Dim BMRange As Word.Range 'if you've got a reference to MSWord.
or
dim BMRange as Object 'if you're using late binding (no reference)
 
Back
Top