?
Solved

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

Posted on 2013-11-08
1
Medium Priority
?
861 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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

762 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