Solved

Excel VBA and Word

Posted on 2013-05-26
3
340 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks very much
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

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,…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

772 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

9 Experts available now in Live!

Get 1:1 Help Now