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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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