Issue: After run Macro vba, all worksheets auto closed without a warning message

anna99

New Member
Joined
Jan 8, 2021
Messages
18
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Hi All,

I run a VBA code from my personal vba to open a closed workbook and then close this workbook with the code below. the issue is with all current active workbooks, when i close, there is no warning message "Do you want to save...." it's just closed without saving. until i close all current excel files and start excel again this issue will disappear. could you please help.

VBA Code:
Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files (*.xls*),*xls*")
    If FileToOpen <> False Then
        Set OpenBook = Application.Workbooks.Open(FileToOpen)
        OpenBook.Sheets("Sheet1").Range("G1:L62").Copy
        mainWS.Range("G1").PasteSpecial xlPasteAll
        OpenBook.Close False
        
    End If
    Application.ScreenUpdating = True
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

rollis13

Active Member
Joined
Jul 30, 2012
Messages
415
Office Version
  1. 2016
Platform
  1. Windows
That's because you aren't setting Application.DisplayAlerts = False back to Application.DisplayAlerts = True before the End Sub.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,794
Messages
5,626,924
Members
416,209
Latest member
tan21

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
Top