Cannot seem to activate original window on open

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
My code below strips away a lot of the excel features that make it excel. The thing is i developed this as a class and only to make the changes to the initial window/ sheet. So I wanted these effects to apply to every sheet so I added a for loop and declared an intitial window variable to make sure i go back to the initial window after applying all effects. However it keeps drawing a object variable or with block variable not set.

Any ideas?

Code:
Public Sub GuiUpgrade()
    
    Dim Sheet As Worksheet
    Dim InitialWindow As Window
    
    'Excel UI Removal
    Application.ScreenUpdating = False
    
    With ThisWorkbook.Application
        .Cursor = xlNorthwestArrow
        .ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
        .DisplayFormulaBar = False
        .DisplayStatusBar = False
    End With
    
    InitialWindow = ThisWorkbook.Application.ActiveWindow
    
    For Each Sheet In ThisWorkbook.Sheets
    
        Sheet.Activate
        
        With ThisWorkbook.Application.ActiveWindow
            .DisplayWorkbookTabs = False
            .DisplayHorizontalScrollBar = False
            .DisplayVerticalScrollBar = True
            .DisplayGridlines = False
            .DisplayHeadings = False
        End With
    
    Next Sheet
    
    InitialWindow.Activate
    
    Application.ScreenUpdating = True


    
    'Update Caption on Window Frame
    With ThisWorkbook.Application
        .ActiveWindow.Caption = ""
        .Application.Caption = "Application Name"
    End With
    
    
End Sub
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I think you are missing this...

Set InitialWindow = ThisWorkbook.Application.ActiveWindow
 
Last edited:
Upvote 0
what do you mean by "original window" , are referring to sheet?
 
Upvote 0
what do you mean by "original window" , are referring to sheet?

Yea, I though capturing the initial window as a variable and then activating it again at the very end would take me back to the original sheet. I find the window object very confusing since in my understanding the sheet is related to the window. For instance, I cannot disable gridlines without first switching to the sheet. I am following some logic form a thread on stackexchange and at the end it sets the initial window active at the very end similar to what I am doing. Whats the point of that then if its not going to switch back to the original sheet.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,737
Members
449,050
Latest member
excelknuckles

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