Workbook_BeforeClose, Makro stops working when Workbook is shared

Aquacat11

New Member
Joined
Oct 12, 2016
Messages
2
Hello everyone,
I have an unexpected problem that i hope some of you can help me with.

I have recently made an Excel Workbook with some Makros inside, to help some of my coworkers plan and log their daily activities,
My Makros, which are placed in the entire workbook, not in modules or at single sheets, looks like this:

Private Sub Workbook_Open()
If (Range("CC156") <> (Range("CA156"))) Then
Call NewWeek
End If
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets(1).Activate
ActiveWorkbook.Save
End Sub

In short, the first makro checks if we're entered a new week when the workbook is opened, and if its the case, then it calls another makro called NewWeek, which creates a new sheet for them to write notes in, and names that sheet (Week 41 etc) and so on,
For this to work i need to make sure that the workbook is always closed on the most recent sheet, so it will check if the most recent sheet week name is matched by the current week, otherwise it would keep making new sheets every time the workbook is opened, if the users close it down while working inside earlier weeks like week 38.
This is the reason for the last part of the shown makro above.

Now to the problem, this concept worked perfectly for me during test phase, and once i was ready to release the workbook, i shared the workbook for all of our sales personal to use, but once i decided to share the workbook, the Workbook_BeforeClose simply stops being executed when anyone closes the workbook(at most it executes only onces, the first time anyone closes it, but then never again), this results in multiple episodes where people would close the workbook down while on earlyer week sheets, causing the workbook to create new sheets every time its opened, the second i unshared the workbook, all of my makros would run perfectly once again. So why does it disable this one importent makro once the file is shared? and how can i fix it?

If the problem is simply an issue with shared workbooks, and cannot be helped at all, maybe i should look into another way to check if the latest sheet was created in the current week, no matter which sheet is currently active once the workbook is opened, any thoughts?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I think i found a working quickfix, it might not be pretty, but it seems to get the job done,
What i did was add the formula Worksheets(1).Activate to the start of my my Workbook_Open sub, this way i have a double failsafe in case the sheet does'nt go to the most recent sheet when its closing, it will when opening, before checking the current week number.
 
Upvote 0

Forum statistics

Threads
1,215,351
Messages
6,124,445
Members
449,160
Latest member
nikijon

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