0

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

3 Answers 3

2

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
1

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.