hellebore08
Board Regular
- Joined
- May 31, 2011
- Messages
- 77
Hi,
I have a macro from attachmate that transfers data to an excel file. My problem is that i can't get these lines to work correctly (code that I use from Attachmate Extra!).
What I need is to attach the macro to an existing excel file - if the excel is already open. And if it is not open, i want the macro to create a new instance of excel and then attach to the newly opened file.
What it does so far is the getobject only but is not creating a new instance of excel when it is not opened. Hope you can help me.. thanks!
I've tried adding an errorhandler but found no luck to make it work. Below is my code with errorhandler:
I have a macro from attachmate that transfers data to an excel file. My problem is that i can't get these lines to work correctly (code that I use from Attachmate Extra!).
Code:
Set obj = Getobject("H:\ultimate.xls")
if obj is nothing then
set obj = CreateObject("Excel.Application")
obj.Workbooks.Open FileName:="H:\ultimate.xls"
end if
obj.visible = true
What I need is to attach the macro to an existing excel file - if the excel is already open. And if it is not open, i want the macro to create a new instance of excel and then attach to the newly opened file.
What it does so far is the getobject only but is not creating a new instance of excel when it is not opened. Hope you can help me.. thanks!
I've tried adding an errorhandler but found no luck to make it work. Below is my code with errorhandler:
Code:
On Error GoTo openerrorh
Set obj = Getobject("H:\ultimate.xls")
obj.visible = true
exit sub
openerrorh:
Set obj = CreateObject("Excel.Application")
obj.Workbooks.Open FileName:="H:\ultimate.xls"
end sub