Open two Excel Workbooks

Rats

Registered User.
Local time
Today, 15:38
Joined
Jan 11, 2005
Messages
151
I use Excel to display some results from my database "Debt ProjectorXLS" the code below without the red text was used successfully to open the Workbook. However, I have some cells in the workbook that reference another workbook which wont update unless the other workbook "ProgressReportXL" is open. Both workbooks have userforms as the user interface but I dont want the user form for "ProgressReportXL" to show when I open it. Basically just open the workbook long enough for the references to update and then close down and while it is open it remains invisible. I changed my existing code to what is shown below as a start point but when it runs it displays the userform for "ProgressReportXL" and nothing else happens until I hit the close button on the form which closes Excel. This closes the form and stops "Debt ProjectorXLS" from opening.

Can anybody suggest some mods to this code which will:-
a. Work if Excel is already open or closed.
b. Open both workbooks but close "ProgressReportXL" once updates have occurred.
c. The process of opening "ProgressReportXL" is transparent to the user. i.e. the userform is not displayed.
d. Failing all of that any suggestions on how I could achieve the above some other way.

Thankyou

Code:
 'Opening Excel to view reports
Dim oApp As Object
'MsgBox "Opening Reports.....There maybe a short delay!", vbInformation, "Debt Projector Reports"
    Set oApp = CreateObject("Excel.Application")
    
   oApp.Visible = True
   
   On Error Resume Next
  [COLOR="Red"] oApp.Workbooks.Open DLookup("[link]", "links", "[linkname]='ProgressReportXL'")[/COLOR]
  oApp.Workbooks.Open DLookup("[link]", "links", "[linkname]='Debt Projectorxls'")
 
I don't know if it will help, but I use the Excel reference and the following code to connect to Excel.

Code:
'Excel variables required for Connection
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet

'Connect to Excel
Set xlapp = New Excel.Application

'Open the file
With xlapp
    'make it visible on screen
    .Visible = True
    
    'set the filepath to be opened - IF FILE CHANGES, ALTER THIS LINE
    Set xlbook = .Workbooks.Open("C:myfile.xls")
        
    'Set worksheet to move within the file
    Set xlsheet = xlbook.Worksheets("worksheet name")
    xlsheet.Select
    
End With

If you make a second one with XLapp2 for example - and set the .Visible to False then I think that achieve your goal of the second one being invisible to the user.
 

Users who are viewing this thread

Back
Top Bottom