I found the following code online. It "works." However, I am having trouble opening the document it creates.
Sub CreateNewWordDoc()
' to test this code, paste it into an Excel module
' add a reference to the Word-library
' create a new folder named C:\Foldername or edit the filnames in the code
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
'Set wrdDoc = wrdApp.Documents.Add ' create a new document
' or
Set wrdDoc = wrdApp.Documents.Open("C:\test\EOR_form.dotm")
' open an existing document
' example word operations
With wrdDoc
For i = 1 To 100
.Content.InsertAfter "Here is a example test line #" & i
.Content.InsertParagraphAfter
Next i
' If Dir("C:\test\MyNewWordDoc.doc") <> "" Then
' Kill "C:\test\MyNewWordDoc.doc"
' End If
.SaveAs ("C:\test\test2.doc") '<-----DOCUMENT TYPE HERE
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
If I use document type .doc I get an error message when the document opens & trys to convert "Word cannot start the converter mswrd632.wpc" but after hitting OK 3 times, it opens.
If I used document types .docx or .docm I get an error message that says, "the file test.docx cannot be opened because there are problems with the contents." After pressing the DETAILS button, it reads "No error detail available."
It is happening because my template is a macro enabled word document.
If I create a new document and save as .doc or .docx it will open. However, if I save it as .docm then I get the get an error message that says, "the file test.docx cannot be opened because there are problems with the contents." After pressing the DETAILS button, it reads "No error detail available."
Bookmarks