Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Problem when adding an Userform by code?

  Asked By: Glenn    Date: Nov 03    Category: MS Office    Views: 857
  

I want to add an userform by code in my module code.

Sub AddAnUserForm()
Dim MyUserform As Object
Set MyUserform = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
End Sub

When i run this code, i get an error for the first time like:

Run-time error '1004':
"Access to the VB Project by programming is not safe"

Note:This is a translation because it was in my language. The sentence is
something like this.

Next time and other times i get an another error:

Run-time error '1004':
"Method 'VBProject' of object '_Workbook' failed"

Any Ideas? How can i create an Userform by Code?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Edna West     Answered On: Nov 03


Try Tools / Macro / Security / Trusted Sources, Trust access to Visual Basic
Project.



There is a reference to this information in my TechTrax article under the
heading “Security Issues” at:

pubs.logicalexpressions.com/.../LPMArticle.asp

(Even though that article is about the VBA Extensibility Library.)

 
Didn't find what you were looking for? Find more on Problem when adding an Userform by code? Or get search suggestion and latest updates.




Tagged: