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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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,214,848
Messages
6,121,914
Members
449,054
Latest member
luca142

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