ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to get an object reference to an ALREADY open excel spreadshee (https://www.excelbanter.com/excel-programming/320818-how-get-object-reference-already-open-excel-spreadshee.html)

JP

How to get an object reference to an ALREADY open excel spreadshee
 
I need to manipulate an already open excel spreadsheet using VBScript. My
problem is that I can't seem to be able to get an object reference to excel
if it's open already. I was able to open an excel workbook and add a sheet,
but I wasn't able to connect to a spreadsheet it if it was already open.
Anybody knows how to do it in VBScript?
E.g: manually open MS Excel and type something in Sheet1. Then when you'd
run this VBScript that I need, it would connect to Sheet1 and would display
the content of it in a message box.

Thanks a lot!
JP

Tom Ogilvy

How to get an object reference to an ALREADY open excel spreadshee
 
have you tried using GetObject instead of CreateObject?

Assuming you are NOT talking about Excel VBA when you say VBScript

--
Regards,
Tom Ogilvy

"JP" wrote in message
...
I need to manipulate an already open excel spreadsheet using VBScript. My
problem is that I can't seem to be able to get an object reference to

excel
if it's open already. I was able to open an excel workbook and add a

sheet,
but I wasn't able to connect to a spreadsheet it if it was already open.
Anybody knows how to do it in VBScript?
E.g: manually open MS Excel and type something in Sheet1. Then when you'd
run this VBScript that I need, it would connect to Sheet1 and would

display
the content of it in a message box.

Thanks a lot!
JP




Bob Phillips[_7_]

How to get an object reference to an ALREADY open excel spreadshee
 
JP,

Try using

Set xlApp = GetObject(,"Excel.Application")

rather than

Set xlApp = CreateObject("Excel.Application")

or better still, use both

Set xlApp = Nothing
On Error Resum Next
Set xlApp = GetObject(","Excel.Application")
On Error Goto 0
If xlApp Is Nothing
'no instance of Excel running, so create one
Set xlApp = CreateObject("Excel.Application")
If xlApp Is Nothing Then
MsgBox "Fatal error"
Exit Sub
End If
End If

--
HTH

Bob Phillips

"JP" wrote in message
...
I need to manipulate an already open excel spreadsheet using VBScript. My
problem is that I can't seem to be able to get an object reference to

excel
if it's open already. I was able to open an excel workbook and add a

sheet,
but I wasn't able to connect to a spreadsheet it if it was already open.
Anybody knows how to do it in VBScript?
E.g: manually open MS Excel and type something in Sheet1. Then when you'd
run this VBScript that I need, it would connect to Sheet1 and would

display
the content of it in a message box.

Thanks a lot!
JP




JP

How to get an object reference to an ALREADY open excel spread
 
Thank You!
JP

"Tom Ogilvy" wrote:

have you tried using GetObject instead of CreateObject?

Assuming you are NOT talking about Excel VBA when you say VBScript

--
Regards,
Tom Ogilvy

"JP" wrote in message
...
I need to manipulate an already open excel spreadsheet using VBScript. My
problem is that I can't seem to be able to get an object reference to

excel
if it's open already. I was able to open an excel workbook and add a

sheet,
but I wasn't able to connect to a spreadsheet it if it was already open.
Anybody knows how to do it in VBScript?
E.g: manually open MS Excel and type something in Sheet1. Then when you'd
run this VBScript that I need, it would connect to Sheet1 and would

display
the content of it in a message box.

Thanks a lot!
JP





JP

How to get an object reference to an ALREADY open excel spread
 
Thank You very much! Great help!
JP

"Bob Phillips" wrote:

JP,

Try using

Set xlApp = GetObject(,"Excel.Application")

rather than

Set xlApp = CreateObject("Excel.Application")

or better still, use both

Set xlApp = Nothing
On Error Resum Next
Set xlApp = GetObject(","Excel.Application")
On Error Goto 0
If xlApp Is Nothing
'no instance of Excel running, so create one
Set xlApp = CreateObject("Excel.Application")
If xlApp Is Nothing Then
MsgBox "Fatal error"
Exit Sub
End If
End If

--
HTH

Bob Phillips

"JP" wrote in message
...
I need to manipulate an already open excel spreadsheet using VBScript. My
problem is that I can't seem to be able to get an object reference to

excel
if it's open already. I was able to open an excel workbook and add a

sheet,
but I wasn't able to connect to a spreadsheet it if it was already open.
Anybody knows how to do it in VBScript?
E.g: manually open MS Excel and type something in Sheet1. Then when you'd
run this VBScript that I need, it would connect to Sheet1 and would

display
the content of it in a message box.

Thanks a lot!
JP






All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com