Solved

Excel VBA and Word

Posted on 2013-05-26
3
354 Views
Last Modified: 2013-06-01
Hi

I am looking for free online literature on Excel VBA code to control Word from
Excel.
0
Comment
Question by:murbro
3 Comments
 
LVL 9

Accepted Solution

by:
skipper68 earned 250 total points
ID: 39197943
http://www.mrexcel.com/forum/excel-questions/43572-using-visual-basic-applications-excel-control-word.html

or

http://stackoverflow.com/questions/15005723/activate-word-window-from-excel-with-vba
Getting an instance of Word will allow you to access the ActiveDocument or the Application's current Selection. Remember to do error checking to make sure you've got what you want.

    Sub GetWordDocument()
        Dim wdApp As Object

        'Turn off error handling since if the Application is not found we'll get an error
        'Use Late Binding and the GetObject method to find any open instances of Word
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        On Error GoTo 0

        'Check to see if we found an instance.  If not you can create one if you desire
        If wdApp Is Nothing Then
            MsgBox "No instances of Word found"
            Exit Sub
        End If

        'Check if there are documents in the found instance of Word
        If wdApp.Documents.Count > 0 Then
            wdApp.Selection.TypeText "Cool, we got it" & vbCr

            'You can now access any of the active document properties too
            wdApp.ActiveDocument.Range.InsertAfter "We did indeed"
        End If

        'Clean up the Object when Finished
        Set wdApp = Nothing
    End Sub
0
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 250 total points
ID: 39199652
Hi,

Here are some Previously Asked Questions I contributed to:

"VBA: From Excel to Words..." (October 2005)
[ http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_21613510.html ]

"Populate Doc file with data from VB" (December 2005)
[ http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21673639.html ]

"I need some VBA code to move data from excel to Word Bookmarks" (June 2006)
[ http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_21896385.html ]

BFN,

fp.
0
 

Author Closing Comment

by:murbro
ID: 39212507
Thanks very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

895 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

14 Experts available now in Live!

Get 1:1 Help Now