I have a Word doc with bookmarks that are filled from an access sql statement. My problem is that I recently switched to using a Range so I could change the text once in Word so as not to destroy my bookmarks. I get an error:
Requested member of the collection does not exist.
My code below:
Private Sub Combo2_AfterUpdate()
Dim BMRange As Range, BM2Range As Range, BM3Range As Range, BM4Range As Range
Dim objWord As Word.Application
' Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application"
With objWord
' Make the application visible.
.Visible = True
' Open the document.
.Documents.Open ("c:\my documents\Intro70.doc"
'Identify current bookmark range and insert text
Set BMRange = ActiveDocument.Bookmarks ("ShipName".Range
BMRange.Text = HULLINFO.ShipName
'Re-insert the bookmark
Selection.Bookmarks.Add "ShipName", BMRange
Set BM2Range = ActiveDocument.Bookmarks("CVNnum".Range
BM2Range.Text = HULLINFO.CVNUM
'Re-insert the bookmark
Selection.Bookmarks.Add "CVNnum", BM2Range
Set BM3Range = ActiveDocument.Bookmarks("ShipName2".Range
BM3Range.Text = HULLINFO.ShipName
'Re-insert the bookmark
Selection.Bookmarks.Add "ShipName2", BM3Range
Set BM4Range = ActiveDocument.Bookmarks("CVNnum2".Range
BM4Range.Text = HULLINFO.CVNUM
'Re-insert the bookmark
Selection.Bookmarks.Add "CVNnum2", BM4Range
'Was using selection
'.ActiveDocument.Bookmarks("HullName".Select
'.Selection.Text = HULLINFO.ShipName
'.ActiveDocument.Bookmarks("HullName2".Select
'.Selection.Text = HULLINFO.ShipName
'.ActiveDocument.Bookmarks("CVNnum".Select
'.Selection.Text = HULLINFO.CVNUM
'.ActiveDocument.Bookmarks("CVNnum2".Select
'.Selection.Text = HULLINFO.CVNUM
End With
'Word.FilePrint 0
' To send the record directly to the printer, unremark the line
' above, and remark the next two lines below.
' Print the document in the foreground so Microsoft Word 97
' will not close until the document finishes printing.
''objWord.ActiveDocument.PrintOut Background:=False
' Close the document without saving changes.
''objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' Quit Microsoft Word 97 and release the object variable.
''objWord.Quit
''Set objWord = Nothing
Exit Sub
End Sub
Any suggestions??
Rae
Requested member of the collection does not exist.
My code below:
Private Sub Combo2_AfterUpdate()
Dim BMRange As Range, BM2Range As Range, BM3Range As Range, BM4Range As Range
Dim objWord As Word.Application
' Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application"
With objWord
' Make the application visible.
.Visible = True
' Open the document.
.Documents.Open ("c:\my documents\Intro70.doc"
'Identify current bookmark range and insert text
Set BMRange = ActiveDocument.Bookmarks ("ShipName".Range
BMRange.Text = HULLINFO.ShipName
'Re-insert the bookmark
Selection.Bookmarks.Add "ShipName", BMRange
Set BM2Range = ActiveDocument.Bookmarks("CVNnum".Range
BM2Range.Text = HULLINFO.CVNUM
'Re-insert the bookmark
Selection.Bookmarks.Add "CVNnum", BM2Range
Set BM3Range = ActiveDocument.Bookmarks("ShipName2".Range
BM3Range.Text = HULLINFO.ShipName
'Re-insert the bookmark
Selection.Bookmarks.Add "ShipName2", BM3Range
Set BM4Range = ActiveDocument.Bookmarks("CVNnum2".Range
BM4Range.Text = HULLINFO.CVNUM
'Re-insert the bookmark
Selection.Bookmarks.Add "CVNnum2", BM4Range
'Was using selection
'.ActiveDocument.Bookmarks("HullName".Select
'.Selection.Text = HULLINFO.ShipName
'.ActiveDocument.Bookmarks("HullName2".Select
'.Selection.Text = HULLINFO.ShipName
'.ActiveDocument.Bookmarks("CVNnum".Select
'.Selection.Text = HULLINFO.CVNUM
'.ActiveDocument.Bookmarks("CVNnum2".Select
'.Selection.Text = HULLINFO.CVNUM
End With
'Word.FilePrint 0
' To send the record directly to the printer, unremark the line
' above, and remark the next two lines below.
' Print the document in the foreground so Microsoft Word 97
' will not close until the document finishes printing.
''objWord.ActiveDocument.PrintOut Background:=False
' Close the document without saving changes.
''objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' Quit Microsoft Word 97 and release the object variable.
''objWord.Quit
''Set objWord = Nothing
Exit Sub
End Sub
Any suggestions??
Rae