Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Excel Hidden

Status
Not open for further replies.

Hmadyson

Programmer
Mar 14, 2001
202
0
0
US
I have to create a program that opens Excel as hidden, launches a spreadsheet, and then waits a little bit and makes Excel visible. This seems like it should be easy, but excel will always be running code, because it asks for some user input.

The first thing that I tried was declaring xl, opening the spreadsheet, then waiting a little bit and making xl visible. This did not work because I never got the control back to my program, since xl kept churning.

The second thing that I tried was launching the spreadsheet from a shell hidden. The problem was that I don't know how to find that xl that just opened to make it visible. There could be multiple Excel sessions open (all with the same caption, so that does me no good).

Does anyone have any ideas?

Thanks.
 
Dear Hmadyson,

would this serve your needs? If not , why not?

Public Sub openexcelhidden()
Dim xl As Excel.Application
Set xl = New Excel.Application
xl.Visible = False
xl.Workbooks.Open "c:\projekte\tektipps\excel9.xls"
'in the open event I have put an inputbox so it pops up
' and the following code is executed after I clicked ok for the inputbox of excel

xl.Visible = True

End Sub

you could also run a (public) macro by using xl.run "Macroname" but then Excel itself has to know when to show up. Also when you use another event than the open event of the workbook Excel itself has to know when to become visible.

HTH
regards Astrid


 
Hi. Perhaps this will help. There are multiple ways you can do this. One would be sort of like this (if you truly don't care what's happening with excel, you just want to make your program wait a bit)

dim xlfile as excel.application
set xlfile = new excel.application
xlfile.visible = false
'do whatever you need here
Sleep 100 'or however long you want to sleep in milleseconds
xlfile.visible = true

NOTE: you need to declare the sleep function in your program. It looks like this:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

 
For some reason my code was not executing the statement after workbook.open, (assumingly because excel is still running code). If I can get the focus back to the vb program this is exactly what I need to do.
 
Dear Hmadyson,

if excel is still working, then in fact you have to wait .
Or you need to do threading, and I am not sure in how far you really want to deal with that.

did you try the same code with an empty workbook? Just to see if it works at all.


regards Astrid
 
Why don't you try with a visible instance of excel to see what is the code that not allows your code to continue?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top