启动此工作表时,我收到“object_global失败的方法工作表”错误。让我感到困惑的是,wc_user_update宏在没有从workbook_open事件调用时运行正常。此外,当我在工作簿打开事件中注释掉密码保护时,它仍然无法正常工作。所以问题似乎在于我如何从Workbook_Open事件中调用wc_user_update宏。我错过了一些明显的东西吗?
ThisWorkbook中的代码:
Private Sub Workbook_Open()
'Dim ws As Worksheet
'For Each ws In Worksheets
'ws.Protect password:="x", UserInterfaceOnly:=True
'Next ws
wc_user_update
End Sub
标准模块中的代码:
Public Sub wc_user_update()
'Ask user if he wants to update usernames. If yes, prompt for credentials
Dim update As Variant
'On Error GoTo ErrorHandler
With Worksheets("WC_USERS")
update = MsgBox("Usernames have not been updated in " & .Range("wc_names_last_updated_days").Value & " days. Would you like to update now?", vbYesNo)
End With
If update = vbYes Then
'show the windchill authentication userform centered in the excel window
With wc_auth
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
'Do stuff
'update "last updated date" cell
Worksheets("WC_USERS").Range("wc_names_last_updated_date").Value = Date
Unload wc_auth
Else
MsgBox ("usernames not updating")
End If
ErrorHandler:
End Sub
答案 0 :(得分:0)
看起来问题是我需要使用ThisWorkbook来限定Worksheets(" WC_USERS")。我还更改了变量名称"更新" to" update_choice。"它现在正在工作。