nyconfidential
New Member
- Joined
- Jul 22, 2015
- Messages
- 49
- Office Version
- 365
- 2016
Hi all - I'm trying to open up a workbook from VBA in Word. Works fine, in the sense that the workbook opens - but when I try to reference the workbook from code in Word, my code thinks that an Excel add-in file that loads on startup is the workbook I just opened(lets call it "MAddIn.xlam"). See the code below - Excel thinks that "oWB" is "MAddIn.xlam", not "MyFile.xlsm"(If I type in "?oWB.name" in the immediate window, it returns "MAddIn.xlam"). Can anyone tell me what I'm doing wrong, and how I can get oWB to reference "MyFile.xlsm" instead of "MAddIn.xlam"? Thanks.
Code:
Sub OpenExcelFile()
Dim oExcel As Excel.Application
Dim oWB As Workbook
Set oExcel = New Excel.Application
Set oWB = oExcel.Workbooks.Open("G:\MyFile.xlsm")
oExcel.Visible = True
End Sub