LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default More then 1 Excel object running at same time , how can I refer to right one in code?

Hi Dave,

I have an access application which opens an new excel application in the
background ( Set ExcelApp = New Excel.Application) and does it 'stuff' no
problem, to keep down the code lines I have use the same 'Public Sub'
proceedure with different values to get data from the excel spreadsheet in
the background.


The way to do this is to either (a) declare ExcelApp as a global variable, do
the 'Public sub' doesn't need to set it to anything:



Dim ExcelApp As Excel.Application

Sub Caller()

Set ExcelApp = New Excel.Application

DoSomething ExcelApp
End Sub

Public Sub DoSomething()

With ExcelApp.ActiveSheet
...
End With
End Sub


Or pass the instance into the 'public sub':

Sub Caller()

Dim ExcelApp As Excel.Application

Set ExcelApp = New Excel.Application

DoSomething ExcelApp
End Sub

Public Sub DoSomething(ByRef ExcelApp As Excel.Application)

With ExcelApp.ActiveSheet
...
End With
End Sub

Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk


 
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
Possible to refer to a sheet's object name ? kittronald Excel Worksheet Functions 1 August 23rd 11 11:30 PM
make camera object refer to dynamic range Mica Excel Discussion (Misc queries) 0 March 27th 10 12:14 AM
How to refer to a cell format code? A difficult problem Excel Discussion (Misc queries) 1 May 25th 05 08:42 AM
refer to the sheets Name property in my code (not what is on the Tab) Sandy[_5_] Excel Programming 3 January 29th 04 08:45 PM
Excel Object in VB when running under scheduler control Peter Hoyler Excel Programming 2 December 17th 03 12:54 PM


All times are GMT +1. The time now is 12:29 PM.

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"