I have some code that I wrote in Excel 2000 that opens a word document and places data from a specifc cell to a bookmark in word.
I need to use that code but with office 2003 and I can't get it to work. It fails when trying to Goto the bookmark no matter what I try. I recorded a macro in word and used this in Excel with the ActiveDocument pre-fix, but to no avail. Here's my code: -
Private Sub CommandButton1_Click()
Const wdWindowStateMaximize As Integer = 1
Const wdNormalView As Integer = 3
Const wdAlignParagraphCenter As Integer = 1
Const wdPageFitFullPage As Integer = 1
Const wdGoToLine As Integer = 3
Dim WordDoc As Object
Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
.WindowState = wdWindowStateMaximize
WordApp.Documents.Open Filename:="C:\Documents and Settings\dfishkin\Desktop\Test quotes\Dave.doc"
Set WordDoc = .Activedocument
End With
WordDoc.ActiveWindow.View = wdNormalView
WordDoc.ActiveWindow.Selection.GoTo What:=wdGoToBookmark, Name:="Dave"
'Stops here with an application defined or object defined error
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
Any help appreciated
I need to use that code but with office 2003 and I can't get it to work. It fails when trying to Goto the bookmark no matter what I try. I recorded a macro in word and used this in Excel with the ActiveDocument pre-fix, but to no avail. Here's my code: -
Private Sub CommandButton1_Click()
Const wdWindowStateMaximize As Integer = 1
Const wdNormalView As Integer = 3
Const wdAlignParagraphCenter As Integer = 1
Const wdPageFitFullPage As Integer = 1
Const wdGoToLine As Integer = 3
Dim WordDoc As Object
Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
.WindowState = wdWindowStateMaximize
WordApp.Documents.Open Filename:="C:\Documents and Settings\dfishkin\Desktop\Test quotes\Dave.doc"
Set WordDoc = .Activedocument
End With
WordDoc.ActiveWindow.View = wdNormalView
WordDoc.ActiveWindow.Selection.GoTo What:=wdGoToBookmark, Name:="Dave"
'Stops here with an application defined or object defined error
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
Any help appreciated