reference the currenlty open Excel from Word

E

Essam Salah

Hi All

I need to create a menu item in word that will get the selection of the
current open Excel sheet and then creates a table in word and populate it
with the data within the selection of Excel.

I know how to create the menu, create word table , etc...
but how to get a ref. to the Excel window

I tried the following code :
<------------------- >
Dim excl As Excel.Application
Set excl = CreateObject("Excel.Application")
MsgBox excl.Windows.Count

</------------------>

but it gives [ 0 ] , while I have one Excel window open !!!

Any Advice

Essam
 
T

Tom Winter

CreateObject may well be creating a new instance of Excel. You should try
GetObject first to get the currently running instance of Excel.

-Tom
 
P

Pranav Wagh

Try this,
Sub x()
Dim excl As Object
Set excl = GetObject(, "Excel.Application")
MsgBox excl.Windows.Count
End Sub
--
Thank You..
Pranav Wagh, MCP, MCSD
Developer Support - Office Integration
Microsoft India(R & D) Pvt. Ltd




Tom Winter said:
CreateObject may well be creating a new instance of Excel. You should try
GetObject first to get the currently running instance of Excel.

-Tom


Essam Salah said:
Hi All

I need to create a menu item in word that will get the selection of the
current open Excel sheet and then creates a table in word and populate it
with the data within the selection of Excel.

I know how to create the menu, create word table , etc...
but how to get a ref. to the Excel window

I tried the following code :
<------------------- >
Dim excl As Excel.Application
Set excl = CreateObject("Excel.Application")
MsgBox excl.Windows.Count

</------------------>

but it gives [ 0 ] , while I have one Excel window open !!!

Any Advice

Essam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top