VBA on all workbooks

dooormanny78

New Member
Joined
Sep 29, 2017
Messages
1
Hello,

I'm very new to the VBA world but was able to get my code to work on every workbook that I manually add it too. The code is really simple to just add message boxes before closing the workbook that serve as reminders to myself.

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545 }p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545 ; min-height: 15.0px}</style>Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MsgBox("Does this have Compensation Information?", vbYesNo) = vbYes Then
If MsgBox("Have you added a password?", vbYesNo) = vbNo Then
Cancel = True


End If
End If
End Sub

My question is there a way to have this code automatically be added to every workbook I download onto my system? For reference I'm using a macbook pro with excel 2016 and access to windows 10 parallels. Any help would be appreciated.

Cheers!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
In the ThisWorkbook module of Personal,

Code:
Option Explicit

Dim WithEvents app  As Excel.Application

Private Sub Workbook_Open()
  Set app = Application
End Sub

Private Sub app_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
  If Not Wb Is Me Then
    If MsgBox("Regarding " & Wb.name & ", ..." & vbLf & _
              "... does it have Compensation Information?", vbYesNo) = vbYes Then
      If MsgBox("... have you added a password?", vbYesNo) = vbNo Then
        Cancel = True
      End If
    End If
  End If
End Sub
 
Last edited:
Upvote 0
And don't forget to save Personal after you make the change.
 
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