Solved

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

Posted on 2013-11-08
1
834 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
[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
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

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…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

726 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