I'm getting a "method worksheets of object_global failed" error when a macro is called from the Workbook_Open event. What really confuses me is that the wc_user_update macro runs fine when it is not called from the workbook_open event. Also, when I comment out the password protection in the workbook open event it still doesn't work. So the problem seems to be in how I am calling the wc_user_update macro from the Workbook_Open event. Am I missing something obvious? Thanks in advance!
Code in ThisWorkbook:
Code in a standard module:
Code in ThisWorkbook:
Code:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;">[COLOR=#00008B]Private[/COLOR] [COLOR=#00008B]Sub[/COLOR] Workbook_Open()
[COLOR=#808080] 'Dim ws As Worksheet[/COLOR]
[COLOR=#808080] 'For Each ws In Worksheets[/COLOR]
[COLOR=#808080] 'ws.Protect password:="x", UserInterfaceOnly:=True[/COLOR]
[COLOR=#808080] 'Next ws[/COLOR]
wc_user_update[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]Sub[/COLOR]</code>
Code in a standard module:
Code:
<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit;">[COLOR=#00008B]Public[/COLOR] [COLOR=#00008B]Sub[/COLOR] wc_user_update()
[COLOR=#808080] 'Ask user if he wants to update usernames. If yes, prompt for credentials[/COLOR]
[COLOR=#00008B] Dim[/COLOR] update [COLOR=#00008B]As[/COLOR] [COLOR=#00008B]Variant[/COLOR]
[COLOR=#808080] 'On Error GoTo ErrorHandler[/COLOR]
[COLOR=#00008B] With[/COLOR] Worksheets([COLOR=#800000]"WC_USERS"[/COLOR])
update = MsgBox([COLOR=#800000]"Usernames have not been updated in "[/COLOR] & .Range([COLOR=#800000]"wc_names_last_updated_days"[/COLOR]).Value & [COLOR=#800000]" days. Would you like to update now?"[/COLOR], vbYesNo)
[COLOR=#00008B] End[/COLOR] [COLOR=#00008B]With[/COLOR]
[COLOR=#00008B] If[/COLOR] update = vbYes [COLOR=#00008B]Then[/COLOR]
[COLOR=#808080] 'show the authentication userform centered in the excel window
[/COLOR] [COLOR=#00008B]With[/COLOR] wc_auth
.StartUpPosition = [COLOR=#800000]0[/COLOR]
.Left = Application.Left + ([COLOR=#800000]0.5[/COLOR] * Application.Width) - ([COLOR=#800000]0.5[/COLOR] * .Width)
.Top = Application.Top + ([COLOR=#800000]0.5[/COLOR] * Application.Height) - ([COLOR=#800000]0.5[/COLOR] * .Height)
.Show
[COLOR=#00008B]End[/COLOR] [COLOR=#00008B]With[/COLOR]
[COLOR=#808080] 'Do stuff[/COLOR]
[COLOR=#808080] 'update "last updated date" cell[/COLOR]
Worksheets([COLOR=#800000]"WC_USERS"[/COLOR]).Range([COLOR=#800000]"wc_names_last_updated_date"[/COLOR]).Value = [COLOR=#00008B]Date[/COLOR]
Unload wc_auth
[COLOR=#00008B] Else[/COLOR]
MsgBox ([COLOR=#800000]"usernames not updating"[/COLOR])
[COLOR=#00008B] End[/COLOR] [COLOR=#00008B]If[/COLOR]
ErrorHandler:
[COLOR=#00008B] End[/COLOR] [COLOR=#00008B]Sub
[/COLOR]</code>
Last edited: