E
EricK
I am trying to create a Word document from an Excel macro.
Sub create_doc()
Dim wordApp As Word.Application
Set wordApp = CreateObject("word.application")
With wordApp
.documents.Add ("P:\word\proj.dot")
.Selection.GoTo what:=wdGoToBookmark, Name:="pol_type"
.Selection.TypeText Worksheets("New_Input").Range("h4")
If Worksheets("New_Input").Range("h4") = "Rebate" Then
.Selection.GoTo what:=wdGoToBookmark, Name:="death"
.ActiveDocument.AttachedTemplate.AutoTextEntries("Death
Benefits:").Insert _
Where:=Selection.Range
End If
..ActiveDocument.SaveAs "P:\word\test.doc"
.Quit
End With
Set wordApp = Nothing
End Sub
The macro crashes on the line where it tries to insert the autotext. Any
ideas what I have done wrong? I got the syntax via recording the macro in
Word.
Thanks,
Eric
Sub create_doc()
Dim wordApp As Word.Application
Set wordApp = CreateObject("word.application")
With wordApp
.documents.Add ("P:\word\proj.dot")
.Selection.GoTo what:=wdGoToBookmark, Name:="pol_type"
.Selection.TypeText Worksheets("New_Input").Range("h4")
If Worksheets("New_Input").Range("h4") = "Rebate" Then
.Selection.GoTo what:=wdGoToBookmark, Name:="death"
.ActiveDocument.AttachedTemplate.AutoTextEntries("Death
Benefits:").Insert _
Where:=Selection.Range
End If
..ActiveDocument.SaveAs "P:\word\test.doc"
.Quit
End With
Set wordApp = Nothing
End Sub
The macro crashes on the line where it tries to insert the autotext. Any
ideas what I have done wrong? I got the syntax via recording the macro in
Word.
Thanks,
Eric