XL.Visible=True not working as expected

D

D.P. Roberts

Hello,
I have several vb scripts which are used to open csv files in Excel.
Everything is working fine, except the Excel files are being opened behind
other open windows. It's not a big deal, but rather annoying to have to
minimize my web browsers or other windows to get to the Excel file that was
opened. This is only happening when I run the scripts in Windows 7; when I
run them from Windows XP the Excel files are opened on top of all other
windows as expected. Also, simply opening Excel in Windows 7 works as
expected (the app opens on top of all other windows) - the problem is only
happening when opening Excel from within a script in Windows 7. Here is the
code I am using:

Set XL = CreateObject("Excel.application")
Set XLBook = XL.Workbooks.Open("filename.csv")
XL.Visible = True

Is there another command I can use that will force the Excel application to
open on top?

I've searched around for an answer but have found nothing on this issue, so
any help would be greatly appreciated.

Thanks!
 
S

Scott Ketelaar

Hi,
try adding this bit of code to the end of yours

XL.Application.WindowState = xlMaximized

Hope that helps

--Scott
 
D

D.P. Roberts

Thanks for your reply. I tried adding that line of code but now when I run
the script I get the following error message:

"Unable to set the WindowState property of the Application"

If I substitute "xlMaximized" for its numeric value (-4137), the script
works and Excel opens, but it still opens behind other windows so I'm right
back where I started. Any other ideas?

Thanks...
 

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