I want to edit my UserForm object in VBE with code.
When I use the following, I get an error as in post title:
Sub myTest() ThisWorkbook.VBProject.VBComponents("UserForm1").Properties("Caption") = "myCaption" End Sub
I tried changing “Caption” to “caption”, the same error. Also this error happens when I try to set
Height properties, not always at first time, but when I run the code again to resize.
“Trust access to the VBA project object model” in macro settings is enabled.
Error does not happen when new workbook and UserForm are created. It does happen when UserForm is recreated in workbook in which an error already happened.
Unload UserForm1 or
Set UserForm1 = Nothing before doesn’t help.
For new workbook, if I create UserForm and run this code from a module, but after right clicking on UserForm -> View Object, then I get an error: “Can’t move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.” When I confirm, on consecutive macro runs I’m getting an error as in post title.
The same happens on Excel 2010 and 2016.
May simply try this
Sub myTest() ThisWorkbook.VBProject.VBComponents("UserForm1").Activate ThisWorkbook.VBProject.VBComponents("UserForm1").Properties("Caption") = "myCaption" End Sub
It is working in Excel 2007 and expect to work in any version.
May Please refer my Answer to Post After Import of a Userform into VBComponents Properties cannot be read