UserForm error: Method 'Properties' of object '_VBComponent' failed
UserForm error: Method 'Properties' of object '_VBComponent' failed
我想用代码在 VBE 中编辑我的用户窗体 object。
当我使用以下内容时,出现 post 标题中的错误:
Sub myTest()
ThisWorkbook.VBProject.VBComponents("UserForm1").Properties("Caption") = "myCaption"
End Sub
我试过把"Caption"改成"caption",还是一样的错误。当我尝试设置 Width
或 Height
属性时也会发生此错误,并非总是在第一次,而是当我再次 运行 代码以调整大小时。
编辑 1:
"Trust access to the VBA project object model" 在宏设置中启用。
编辑 2:
创建新工作簿和用户窗体时不会发生错误。当在已经发生错误的工作簿中重新创建用户窗体时,确实会发生这种情况。
编辑 3:
在前面添加 Unload UserForm1
或 Set UserForm1 = Nothing
没有帮助。
编辑 4:
对于新工作簿,如果我从模块创建 UserForm 和 运行 此代码,但在右键单击 UserForm -> View Object 后,我会收到错误消息:"Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus." 当我确认时,在连续的宏 运行s 上,我收到一个错误,如 post title.
编辑 5:
Excel 2010 年和 2016 年也是如此。
可以试试这个
Sub myTest()
ThisWorkbook.VBProject.VBComponents("UserForm1").Activate
ThisWorkbook.VBProject.VBComponents("UserForm1").Properties("Caption") = "myCaption"
End Sub
它在 Excel 2007 年工作,预计在任何版本中工作。
可能 请参考我的回答 Post After Import of a Userform into VBComponents Properties cannot be read
我想用代码在 VBE 中编辑我的用户窗体 object。
当我使用以下内容时,出现 post 标题中的错误:
Sub myTest()
ThisWorkbook.VBProject.VBComponents("UserForm1").Properties("Caption") = "myCaption"
End Sub
我试过把"Caption"改成"caption",还是一样的错误。当我尝试设置 Width
或 Height
属性时也会发生此错误,并非总是在第一次,而是当我再次 运行 代码以调整大小时。
编辑 1: "Trust access to the VBA project object model" 在宏设置中启用。
编辑 2: 创建新工作簿和用户窗体时不会发生错误。当在已经发生错误的工作簿中重新创建用户窗体时,确实会发生这种情况。
编辑 3:
在前面添加 Unload UserForm1
或 Set UserForm1 = Nothing
没有帮助。
编辑 4: 对于新工作簿,如果我从模块创建 UserForm 和 运行 此代码,但在右键单击 UserForm -> View Object 后,我会收到错误消息:"Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus." 当我确认时,在连续的宏 运行s 上,我收到一个错误,如 post title.
编辑 5: Excel 2010 年和 2016 年也是如此。
可以试试这个
Sub myTest()
ThisWorkbook.VBProject.VBComponents("UserForm1").Activate
ThisWorkbook.VBProject.VBComponents("UserForm1").Properties("Caption") = "myCaption"
End Sub
它在 Excel 2007 年工作,预计在任何版本中工作。 可能 请参考我的回答 Post After Import of a Userform into VBComponents Properties cannot be read