View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Opening a Workbook in the Background

Looks like you have declared objApp as a modular variable in the
ThisWorkbook module which will not be visible elsewhere in your project,
such as your sheet modules. In a normal module try -
Public objApp As Excel.Application

To make things easier why not save your Data file as a hidden workbook and
open in the normal way in same instance as your main workbook. Though of
course user might see it in the Window Unhide.

Regards,
Peter T

"g-boy" wrote in message
...
I have a main "front end" workbook that people will be opening to interact
with. Whenever this main workbook opens, I would like it to open another
"data" workbook in the BACKGROUND, so I can copy data back and forth

between
them using various scripts. I don't want the front end user to be able to
see the data sheet, or (ideally) even know that it has been opened in the
background.

In the code for "ThisWorkbook" in the main front end workbook, I have:

Dim objApp As Excel.Application
Private Sub Workbook_Open()
Set objApp = CreateObject("Excel.Application")
objApp.Workbooks.Open ("X:\pathto\Data.xls")
objApp.Visible = False
End Sub

In the code for the main worksheet in the main front end workbook, I have:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim DataSheet As Worksheet
Set DataSheet = objApp.Workbooks("Data.xls").Sheets(1)
[.....]
End Sub

So, with the code as I have shown above, I usually get an "Object
Expected" error on my Set Datasheet line, which makes me think it isn't
recognizing my public objApp variable that I declared in the code for
ThisWorkbook. Should I be declaring it differently?

If I simply remove the "objApp." prefix in that line, of course it says
subscript out of range. If I use a regular Worksheets.Open (instead of
creating a new app object), it brings the Data.xls workbook to the
foreground and I can't figure out how to hide it.... I want the opening of
the Data workbook to be stealthy and hidden, if that is at all

possible....

Any help at all would be most appreciated. Thanks,

---G