Word Automation using Excel VBA

Posted on 2011-02-25
Last Modified: 2013-11-10
I want to generate word report using Excel VBA.
Question by:sachin237
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 22

Expert Comment

ID: 34984985
How about this?

shell Application.Path & "\winword"
LVL 30

Expert Comment

ID: 34985073
I would suggest Late Binding with Word. Here is an Example.

Since you have mentioned much what you want to do with the report, so I have left that area blank in the code.

Sub OpenWordDoc()
    Dim oWordApp As Object, oWordDoc As Object
    Dim FlName As String
    FlName = "C:\MyWordDoc.Doc"
    '~~> Establish an Word application object
    On Error Resume Next
    Set oWordApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Set oWordApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0
    oWordApp.Visible = True
    Set oWordDoc = oWordApp.Documents.Open(FlName)
    '~~> Perform necessary actions.
    oWordDoc.Close Cavechanges:=True
    Set oWordDoc = Nothing
    Set oWordApp = Nothing
End Sub

Open in new window

LVL 30

Accepted Solution

SiddharthRout earned 500 total points
ID: 34985080
I see two typos in the above code.

1) Please read

>>>Since you have mentioned much what you want to do with the report, so I have left that area blank in the code.


Since you haven't mentioned much what you want to do with the report, so I have left that area blank in the code.

2) Line 23 in the code

oWordDoc.Close Cavechanges:=True


oWordDoc.Close Savechanges:=True

Sorry for the typos.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question