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
"EricK" wrote: > 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. What do yo mean by "crashes"? Any error message? Does Word freeze? What is actually selected by "Selection.range" when the code gets there? Which template is used to store the AutoText entries? (Is it "proj.dot"?) You mentionned the macro recorder, you may find the following page interesting and useful: http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm