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
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
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks