PDA

View Full Version : Solved: Cannot switch to an active excel workbook from word



sam3444
07-11-2011, 01:42 PM
Hi,
From a word macro, how can I switch to an excel workbook that is already open to run an excel macro within it?

Any examples online of working with excel through word show the need to open a new instance of excel and open the file in order to have access to it. I would like to avoid this as it takes a long time to open the workbook. And if this cannot be answered, then how could I switch to a specific document in word that is currently open through word vba?

CatDaddy
07-11-2011, 01:46 PM
Me.Application.Workbooks.Open("C:\YourPath\YourWorkbook.xls")

there is a separate forum for word, but i think its Windows(DocumentName).Activate?

Aflatoon
07-12-2011, 12:38 AM
Assuming you know the path of the workbook in question, you can use GetObject:

GetObject("C:\PathToFile\Workbook.xls").Application.Run "macroname"
for example.

sam3444
07-13-2011, 07:22 AM
thank you both for your responses.

CatDaddy
07-13-2011, 10:41 AM
which worked?