Open Excel Workbooks in separate windows

B

Budget Programmer

Hello,
From within a Word macro, how would I open two Excel workbooks each in it's
own visible Window?
Thanks for your help.
 
B

Budget Programmer

I should also Add that I'm checking to see if Excel was running already, so
that I won't inadvertantly close it if I run into a problem with this macro.
Here's some of the code I have related to the workbook opens:
'Start Excel
'If Excel is running, get a handle on it; otherwise start a new instance of
Excel
On Error Resume Next
Set obXlTestApp = GetObject(, "Excel.Application")
If Err Then
blXlExcelWasNotRunning = True
Set obXlTestApp = Excel.Application
End If

On Error GoTo Err_Handler


'Let the Excel application be visible to the user
obXlTestApp.Visible = True

'Open the workbook stored in "vrXlTestTemplateFullname" Note: Open uses the
Folder and Filename (FullName)
Set obXlTestFile = Workbooks.Open(FileName:=vrXlTestTemplateFullName)

'Save the template as a new file using "vrXlTestFullName" Note: Save and
SaveAs uses the Folder and Filename (FullName)
'By using SaveAs, the original template is automatically closed and does not
need to be closed "manually"
ActiveWorkbook.SaveAs FileName:=vrXlTestFullName

'Open the workbook stored in "vrXlTraceTemplateFullname" Note: Open uses the
Folder and Filename (FullName)
Set obXlTraceFile = Workbooks.Open(FileName:=vrXlTraceTemplateFullName)
'Save the template as a new file using "vrXlTraceFullName" Note: Save and
SaveAs uses the Folder and Filename (FullName)
'By using SaveAs, the original template is automatically closed and does not
need to be closed "manually"
ActiveWorkbook.SaveAs FileName:=vrXlTraceFullName

(bunch of code. If there's an error with text from the Word document,
control is transferred to the label "Err_Handler")

'If the workbook obXlTestFile was open (if it was Not Nothing), then close it.
If Not obXlTestFile Is Nothing Then
obXlTestFile.Close
End If

'If the workbook obXlTraceFile was open (if it was Not Nothing), then close
it.
If Not obXlTraceFile Is Nothing Then
obXlTraceFile.Close
End If

'If Excel was runing when this macro started, leave it running. There are
probably other workbooks open.
'If Excel was Not running when this macro started (blXlExcelWasNotRunning =
False) then quit Excel
If blXlExcelWasNotRunning = True Then
obXlTestApp.Quit
End If

'Set the Objects to "Nothing" to initialize the object
Set obXlTestApp = Nothing
'Set obXlTraceApp = Nothing
Set obXlTestFile = Nothing
Set obXlTraceFile = Nothing
Set obXlTestSheet = Nothing
Set obXlTraceSheet = Nothing
Set obXlRange = Nothing
Set obWdApp = Nothing
Set obWdDoc = Nothing
 
G

GEBL

For one Excel file

sub main
Dim objExcel As Object

Set objExcel = CreateObject("Excel.Application")
Set objExcel = GetObject("Path & Filename here")
objExcel.Application.Visible = True
objExcel.Parent.Windows(1).Visible = True

End Sub
 
B

Budget Programmer

Hello,
Thanks, but that did NOT open a separate instance of Excel, making the
second worksheet visible in its own distinct window. They run just like
before where I have to go the single instance of Excel and use the Windows
feature in there to view the two workbooks.
What I'm after is to have the Excel application appear twice on the Windows
Taskbar, each appliaction associated with a different workbook.
Many thanks for your help.
 
J

james_davey1

i havent checked it out, but can you not just:

dim objxl as new excel.application

then open your workbook .... then just do it again for the second one?
 
B

Budget Programmer

Hi,
That's what I've done, but it seems to open both in the same application.
I've Dim'ed two applications and tried to associate one workbook with each
application, but that doesn't seem to work either.
Thanks for looking into thtis
 
N

Nick Hebb

Will setting the ShowWindowsInTaskbar property help?

Dim bShowInTaskbar as Boolean

bShowInTaskbar = objExcel.ShowWindowsInTaskbar
objExcel.ShowWindowsInTaskbar = True

' Do stuff

' Restore user's setting
objExcel.ShowWindowsInTaskbar = bShowInTaskbar


- Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top