Visible = True does not work

jimbenet

New Member
Joined
Mar 10, 2015
Messages
3
Trying to open an Excel spreadsheet from Outlook and have it be visible after opening it. However, the file opens but I have to click on icon to make it visible.
Here is part of the VBA code that I use in Outlook:
------------
Pname = "C:\Users\" & Environ("Username") & "\Documents\Documents\"
Fname = "Words.xlsm"

On Error Resume Next
Set xlApp = GetObject("Excel.Application")
If Err.Number <> 0 Then
On Error GoTo 0
Set xlApp = CreateObject("Excel.Application")
End If
With xlApp
.Workbooks.Open Filename:=Pname & Fname, ReadOnly:=False
.ActiveWorkbook.Activate
.Visible = True
.WindowState = xlMaximized 'maximize Excel
.Application.ScreenUpdating = True
.Application.Run ("'Words.xlsm'!Words")
End With
------------
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi jimbenet and Welcome to the Board! Trial re-arranging your code to make the application visible and then open the file. HTH. Dave
 
Upvote 0
Hi jimbenet and Welcome to the Board! Trial re-arranging your code to make the application visible and then open the file. HTH. Dave
That worked!
I also found another solution. I inserted "DoEvents" between .ActiveWorkbook.Activate and .Visible = True. That worked as well.
I like your solution better though.
Thanks for the tip.
 
Upvote 0
You are Welcome. Thanks for posting your outcome. Dave
The macro works better with DoEvents inserted after CreateObject("Excel.Application").
Here is my final version.

Pname = "C:\Users\" & Environ("Username") & "\Documents\Documents\"
Fname = "Words.xlsm"

On Error Resume Next
Set xlApp = GetObject("Excel.Application")
If Err.Number <> 0 Then
On Error GoTo 0
Set xlApp = CreateObject("Excel.Application")
End If
DoEvents
With xlApp
.Visible = True
.WindowState = xlMaximized 'maximize Excel
.Workbooks.Open Filename:=Pname & Fname, ReadOnly:=False
.Application.ScreenUpdating = True
.Application.Run ("'Words.xlsm'!Words")
End With
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,143
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top