• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Combine 2 macros

akinkaraman

Member
I have 2 macros.

First one asks password if the file is expired and if entering right password it opens Data sheet otherwise it deletes the expired excel file.

Second one asks to accept the macros and if accepting then shows the Data sheet.

My Expired Date file doesn't work if the user doesn't accept the macros so I want it to ask to the user to accept macros, if he accepts than it will check the file if it is expired or not. Then if it is expired then will ask to enter the passcode. At last if it is expired and wrong password then finally it will be deleted.

I want to combine second macro into my first macro to force people to accept macros.

Now I have 2 different ThisWorkbook codes and I couldn't combine them in 1 ThisWorkbook code.

Please help me..

Not: Passcode for first file (Expired Date) is chandoo.
If you enter wrong code it will be deleted.

Thank you..
 

Attachments

  • Expired Date.xlsm
    26.1 KB · Views: 9
  • Force Macros.xlsm
    24.6 KB · Views: 3
Your Force Macros Workbook_Open event is pretty straight-forward
Code:
Private Sub Workbook_Open()
    'Unhide all worksheets
    Application.ScreenUpdating = False
    Call ShowAllSheets
    Application.ScreenUpdating = True
End Sub

To combine this with Expried Date, take the Workbook_Open event from other, but add this line to beginning.
Code:
Private Sub WorkBook_Open()
Call ShowAllSheets
Call ToggleCutCopyAndPaste(False)
'rest of code...
'...
End Sub
 
See attached, where I merged copied the code from one book over to the other.
 

Attachments

  • Combined Macros.xlsm
    35.4 KB · Views: 13
If I want to close the file via the application close button, the application doesn't close so I have to click to close button again to exit.

To fix this; remove ".Close savechanges:=False" line in Workbook_BeforeSave section at ThisWorkbook module. It solves the problem.
 
One more think that I've forgotten to tell.

We should write Sheets("Intro").Visible = xlVeryHidden at the end of the Sub ShowAllSheets() section in Module otherwise if it is not the expired day Intro page is being showed too. So we hide Intro page.
 
Last edited:
Back
Top