Issue with Save and Close macro

ChaosPup

New Member
Joined
Sep 27, 2021
Messages
48
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a couple issues that I don't understand, hoping someone can help.

I have a spreadsheet that everyone uses that opens as full screen with no formula bar, no ribbon etc. (see code for opening below - I use a macro button to save and close, also below). The code itself works fine.

1st issue - I originally used application.close but it closed every other iteration of Excel that someone using the spreadsheet had open (obviously). ThisWorkbook.Close fixes that but I'm left with an empty Excel window, is there any way to close this also?

2nd issue - After using the workbook, every subsequent spreadsheet that is opened is missing its formula bar. It's easy enough to check the View Formula Bar every time, but is there any way to prevent this?

Thanks everyone!

VBA Code:
Sub Workbook_Open()

 ActiveWindow.DisplayGridlines = False
 ActiveWindow.DisplayHeadings = False
 Application.DisplayFormulaBar = False
 Application.DisplayFullScreen = True
 
 End Sub

 Sub Save_and_Close()
   
    ActiveWindow.DisplayGridlines = True
    ActiveWindow.DisplayHeadings = True
    Application.DisplayFormulaBar = True
    Application.DisplayFullScreen = False
    Application.DisplayAlerts = False
    
    ThisWorkbook.Save
    
    ThisWorkbook.Close

End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi,

to solve your issue (1) you might be able to use :
VBA Code:
Application.Workbooks.Count
in order to see if you have >1 workbook open - then you can choose to close the workbook instance, or the application instance (which I guess is better for those having only your sheet open) ?

for item(2) I think its true Excel remembers its last state as such - but perhaps one option again is to turn them back on just before you save and close this workbook in your code above ?

cheers

Rob
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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