VBA to save a workbook's referenced workbooks and add-ins

pizzaboy

Board Regular
Joined
Mar 23, 2015
Messages
56
Office Version
  1. 2019
Platform
  1. Windows
Its pretty annoying having to manually save every related add-in referenced by a workbook. How can I automatically save them upon saving the workbook?


So, in the workbook itself I have code in the "ThisWorkbook" module:
Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
    If Success Then Call Workbook.SaveAll(ThisWorkbook.Name)
End Sub

And in one of my main shared Add-In modules (named "Workbook"), I have:
Code:
    Private Saving_Workbooks As Boolean


    Public Sub SaveAll(pCurrentWorkBook As String)
        Dim wb
        
        If (Not Saving_Workbooks) Then
            
            'prevent infinite loop
            Saving_Workbooks = True
            
            
            For Each wb In Application.Workbooks
                If ((Not wb.ReadOnly) And _
                        (Windows(wb.Name).Visible) And _
                        (wb.Name <> pCurrentWorkBook)) Then
                    wb.Save
                End If
            Next
            
            
            'allow all workbooks to be saved again
            Saving_Workbooks = False
            
        End If
    End Sub


While this works for all opened workbooks (not just directly referenced ones), it doesn't appear to find the add-ins...


Any help would be greatly appreciated.

Cheers
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
No replies?

There have been numerous times I've forgotten to manually save add-ins due to debugging. I'm seriously surprised no-one has incorporated this into their projects...
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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