Open a workbook but not activating or selecting it


Posted by david on August 29, 2000 3:06 AM

I want to be able to open a workbook in the background without being seen at all. Can I do it. I am not interested in hiding at all. I just want it open without focusing on it at all.

Posted by Ivan Moala on August 29, 0100 4:23 AM

David the following routine creates an instance
of an excel file.....hidden....is this what you
are after ??

Option Explicit
Dim xlApp As Excel.Application
Dim sFile As String

Sub OpenWorkBook()

sFile = "D:\xl_useful\14-wilcox.xls"
'Check to see if the file name passed in to
'the procedure is valid
If Dir(sFile) = "" Then
MsgBox sFile & " isn't a valid path!"
Exit Sub
Else
Set xlApp = CreateObject("Excel.Application")
xlfile.Visible = False

xlApp.Workbooks.Open sFile
End If
End Sub

Sub Show()
xlApp.Visible = True
xlApp.Quit
Set xlApp = Nothing
End Sub

Ivan


Posted by david on August 29, 0100 4:52 AM


No I just want it to open but not to see it opening. I want the focus to remain on the current workbook while another workbook is being open through a macro from the first.

The focus needs to stay on the initial workbook.

Posted by Celia on August 29, 0100 4:54 AM


David
If you want to open it without hiding it but not have it activated, you could open it minimized :-

Application.ScreenUpdating = False
Workbooks.Open ("C:\MyFile.xls")
ActiveWindow.WindowState = xlMinimized
ActiveWindow.WindowState = xlMaximized

The last line is to make sure that the window that was active before "MyFile" was opened is maximized.

Celia



Posted by David on August 29, 0100 10:13 PM

Yep that took care of it thank you both.