Results 1 to 3 of 3

Opening an Excel created Word Document (VBA Only) [v2010/14]

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Opening an Excel created Word Document (VBA Only) [v2010/14]

    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."
    Last edited by lloydgodin; 06-07-2012 at 06:04 PM. Reason: narrowed down error

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1