Solved

Word Automation using Excel VBA

Posted on 2011-02-25
3
599 Views
Last Modified: 2013-11-10
Hi
I want to generate word report using Excel VBA.
0
Comment
Question by:sachin237
  • 2
3 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 34984985
How about this?

shell Application.Path & "\winword"
0
 
LVL 30

Expert Comment

by:SiddharthRout
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
    Err.Clear
    On Error GoTo 0
    
    oWordApp.Visible = True
    
    Set oWordDoc = oWordApp.Documents.Open(FlName)
    
    '~~> Perform necessary actions.
    
    oWordDoc.Close Cavechanges:=True
    
    Set oWordDoc = Nothing
    oWordApp.Quit
    Set oWordApp = Nothing
End Sub

Open in new window


Sid
0
 
LVL 30

Accepted Solution

by:
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.

as

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

as

oWordDoc.Close Savechanges:=True

Sorry for the typos.

Sid
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now