Solved

Excel VBA and Word

Posted on 2013-05-26
3
389 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:Murray Brown
[X]
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
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:Murray Brown
ID: 39212507
Thanks very much
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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.

636 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