Reputation: 265
I have a workbook (WorkbookA.xlsm) that I open. Upon being opened, this opens WorkbookB.xlsm.
'ThisWorkbook code of WorkbookA.xlsm
Private Sub Workbook_Open()
Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open(Filename:="C:\WorkbookB.xlsm")
wb.Windows(1).Visible = False
End Sub
After "B" being opened, a script is called that also sets off a timer.
The script in B changes some data on A. I want to add something after the script is called to automatically save WorkbookA.xlsm as it is (without any prompts).
'ThisWorkbook code of WorkbookB.xlsm
Private Sub Workbook_Open()
Call Script
'looking for something in here to save WorkbookA
End Sub
Upvotes: 0
Views: 42
Reputation: 2587
Since you know the name of the workbook you want saved ("WorkbookA.xlsx"), you can reference it directly with a save method:
Workbooks("WorkbookA.xlsx").Save
Upvotes: 2
Reputation: 7679
Try something similar to this:
For each w in Application.Workbooks
If w.Name = "WorkbookA" Then
w.Save
Exit For
End if
Next w
You need to find the workbook you want or set it prior in your code since you want the save code to be called from workbookB. If you were to call it from workbookA, you could use ActiveWorkbook.Save
Upvotes: 0
Reputation: 17327
You can use the Workbook.Save
method to save your workbook. It'll be something like
wb.Save
or
ActiveWorkbook.Save
if you know that your current workbook is the active one. Save
doesn't let you change the filename - if you want that, use SaveAs
instead.
Upvotes: 1