+ Reply to Thread
Results 1 to 2 of 2

referencing an excel cell from word

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2012
    Location
    San Francisco, USA
    MS-Off Ver
    Excel 2007
    Posts
    60

    referencing an excel cell from word

    if i have an excel file and a word file saved in the same folder, how do i reference a cell in the excel file from the word macro?
    lets say for example, I want to reference A3

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: referencing an excel cell from word

    I am not too familiar with Word VBA, but try the code below. You may have to change directory and cell reference to suit your need.

    PS: Make sure Microsoft Object Reference from the library is checked

    Sub Test()
    Dim xlApp As Excel.Application: Set xlApp = CreateObject("Excel.Application")
    Dim xlWB As Excel.Workbook
    
        Set xlWB = xlApp.Workbooks.Open("C:\Users\Jie\Desktop\Test\Test.xlsx")
                With ActiveDocument.Content
                    .InsertAfter xlWB.Worksheets("Sheet1").Cells(1, 1)
                    .InsertParagraphAfter
                End With
        xlWB.Close False
        xlApp.Quit
        Set xlWB = Nothing
        Set xlApp = Nothing
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1