PC Review


Reply
Thread Tools Rate Thread

Accessing another instance of Excel in vba.

 
 
grusenet@gmail.com
Guest
Posts: n/a
 
      14th Nov 2007
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 With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      14th Nov 2007
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


"(E-Mail Removed)" 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 With Quote
 
Tim Williams
Guest
Posts: n/a
 
      15th Nov 2007



"Joel" <(E-Mail Removed)> wrote in message
news:942156B9-541C-4975-8148-(E-Mail Removed)...
> 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




> "(E-Mail Removed)" 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing a Component's Name Instance Craig Microsoft Dot NET Compact Framework 0 27th Dec 2007 02:53 PM
Accessing existing Excel instance Ian Dunn Microsoft VB .NET 3 6th Jul 2006 07:37 AM
Accessing a Running Instance of a Window Marc W. Microsoft C# .NET 1 31st Dec 2003 05:32 PM
Word 97 new instance when accessing a document =?Utf-8?B?Um9u?= Microsoft Word Document Management 0 16th Dec 2003 06:06 PM
Accessing an instance of a form from another class Duane Roelands Microsoft Dot NET Compact Framework 3 3rd Dec 2003 09:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:13 PM.