Solved

Running a VBA macro in Word 2010 to write to an Excel 2010 worksheet

Posted on 2013-11-08
1
830 Views
Last Modified: 2013-11-10
Hi,

I have a macro-enabled word 2010 document.  I am trying to write to an Excel 2010 worksheet from this word doc.  

What declaration are needed in the module in word 2010 for EXCEL to write to a excel 2010 worksheet?

I can write to an excel file by ANY name (don't care what it is) that will contain my destination worksheet

    Dim obWord As Object
    Dim doc As Word.Document
    Dim docTable As Word.Table
    Dim tblRow As Long, tblCol As Long

    'Something is MISSING HERE
    'Lines are needed here to write and excel file that contains the worksheet declared below
    'Please remember that this will be running in  Word 2010
    Dim ws As Worksheet
0
Comment
Question by:jmohsin
1 Comment
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39634121
Here is some code to write to a worksheet from Word. Note that it uses Early binding, so you need to have a reference to the Microsoft Excel Object Library:
Sub xl()
    Dim xlApp As Excel.Application
    Dim xlWbk As Excel.Workbook
    Dim xlWks As Excel.Worksheet
    
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True
    Set xlWbk = xlApp.Workbooks.Add
    Set xlWks = xlWbk.Worksheets(1)
    xlWks.Cells(1, 1).Value = "XXX"

End Sub

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

856 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