Captain Smith
Active Member
- Joined
- Feb 28, 2003
- Messages
- 324
Hello. My code below blows up on the bolded line. From Excel I want to open a word document, delete everything on the word document, then save the word docuemnt. Any suggestions? Thank you.
Sub delete_word()
Dim WdObj As Object, wdcharacter
Set WdObj = Nothing
Set WdObj = CreateObject("Word.Application")
WdObj.Visible = False
WdObj.Documents.Open Filename:=Sheets("Paths").Range("B9").Text & "\Word_Template.docx"
WdObj.Visible = False
WdObj.Selection.WholeStory
WdObj.Selection.Delete , Unit:=wdcharacter, Count:=10000
With WdObj
.ChangeFileOpenDirectory Sheets("Paths").Range("B9").Text
.ActiveDocument.SaveAs Filename:="Word_Template.docx"
End With
With WdObj
.ActiveDocument.Close
.Quit
End With
Set WdObj = Nothing
End Sub
Sub delete_word()
Dim WdObj As Object, wdcharacter
Set WdObj = Nothing
Set WdObj = CreateObject("Word.Application")
WdObj.Visible = False
WdObj.Documents.Open Filename:=Sheets("Paths").Range("B9").Text & "\Word_Template.docx"
WdObj.Visible = False
WdObj.Selection.WholeStory
WdObj.Selection.Delete , Unit:=wdcharacter, Count:=10000
With WdObj
.ChangeFileOpenDirectory Sheets("Paths").Range("B9").Text
.ActiveDocument.SaveAs Filename:="Word_Template.docx"
End With
With WdObj
.ActiveDocument.Close
.Quit
End With
Set WdObj = Nothing
End Sub