Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Accessing another instance of Excel in vba.

Hi

I have written a vba routine which automates Internet Explorer and
causes a web page to output a report in Excel. The web page creates a
new instance of Excel each time it produces the report.
My questions are, firstly, how do I get vba to 'see' the workbook in
the other instance of Excel so that I can save it and secondly, how
can I close the other instance of Excel after saving the file.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Accessing another instance of Excel in vba.

If you know the name of the workbook then use the workbook name

with workbooks("abc.xls") or similar)

If you don't know the name then try something like this

Sub test()

For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
Set otherbook = wbk
End If
Next wbk
If Not IsEmpty(otherbook) Then
otherbook.Close
End If
End Sub


" wrote:

Hi

I have written a vba routine which automates Internet Explorer and
causes a web page to output a report in Excel. The web page creates a
new instance of Excel each time it produces the report.
My questions are, firstly, how do I get vba to 'see' the workbook in
the other instance of Excel so that I can save it and secondly, how
can I close the other instance of Excel after saving the file.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Accessing another instance of Excel in vba.




"Joel" wrote in message
...
If you know the name of the workbook then use the workbook name

with workbooks("abc.xls") or similar)

If you don't know the name then try something like this

Sub test()

For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
Set otherbook = wbk
End If
Next wbk
If Not IsEmpty(otherbook) Then
otherbook.Close
End If
End Sub



That would only work in the same instance of Excel: if another Excel is open
then it has its own separate Workbooks collection.

You could try using GetObject(), but there's no way to be certain of which
instance this would return. In my (brief) testing it seemed to return the
first-opened of two instances, so that's not going to help.

Tim




" wrote:

Hi

I have written a vba routine which automates Internet Explorer and
causes a web page to output a report in Excel. The web page creates a
new instance of Excel each time it produces the report.
My questions are, firstly, how do I get vba to 'see' the workbook in
the other instance of Excel so that I can save it and secondly, how
can I close the other instance of Excel after saving the file.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - New Instance JMay Excel Discussion (Misc queries) 4 November 28th 09 04:55 PM
How do I get one instance of Excel to communicate with another instance? [email protected] Excel Programming 3 November 21st 06 10:31 PM
How to get all Excel instance Xav[_2_] Excel Programming 2 December 24th 05 04:55 PM
Excel Instance FuzzyLogic Excel Programming 2 February 21st 04 03:41 PM
Second instance of Excel Dom[_2_] Excel Programming 1 August 25th 03 05:37 PM


All times are GMT +1. The time now is 04:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"