Save excel workbook into the current workbook automatically with no prompt

HettyA

New Member
Joined
Aug 20, 2020
Messages
5
Office Version
  1. 2007
Platform
  1. Windows
Hello,

How do i save without the prompt to save as every time i run my Vb script. I'd like it to automatically save into my existing workbook rather than open a new path or prompt me to save all the time.

Thanks

'Input Excel File's Full Path
ExcelFilePath = "C:\Users\Student\Desktop\Tester.xlsm"

'Input Module/Macro name within the Excel File
MacroPath = "Sheet1.refresh1"

'Create an instance of Excel
Set ExcelApp = CreateObject("Excel.Application")

'Do you want this Excel instance to be visible?
ExcelApp.Visible = True ' or False

'Prevent any App Launch Alerts (ie Update External Links)
ExcelApp.DisplayAlerts = False

'Open Excel File
Set wb = ExcelApp.Workbooks.Open(ExcelFilePath)

'Execute Macro Code
ExcelApp.Run MacroPath

'Reset Display Alerts Before Closing
ExcelApp.DisplayAlerts = True

'Open workbook; Run Macro; Save Workbook with changes; Close; Quit Excel
Set wbToRun = ExcelApp.Workbooks.Open(ExcelFilePath)
ExcelApp.Run MacroPath ' wbToRun.Name & "!" & MacroPath
wbToRun.Save
wbToRun.Close
ExcelApp.Quit
 

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.
It looks like you have duplicated the process of opening the workbook and running the macro. Maybe if you comment out the second set of commands to open and run it won't display the alert.

Rich (BB code):
'Open Excel File
 Set wb = ExcelApp.Workbooks.Open(ExcelFilePath)

'Execute Macro Code
 ExcelApp.Run MacroPath

'Reset Display Alerts Before Closing
  ExcelApp.DisplayAlerts = True

'Open workbook; Run Macro; Save Workbook with changes; Close; Quit Excel
 Set wbToRun = ExcelApp.Workbooks.Open(ExcelFilePath) 
ExcelApp.Run MacroPath     '   wbToRun.Name & "!" & MacroPath

also you can close and save in one statement.


VBA Code:
 wbToRun.Close  True
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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