I am having issues with writing code that creates a UserForm on Excel 2013. I have searched Microsoft help sites as well as many other sites for solutions, and I have figured out that I don't have a problem with the coding, but it is a problem that I have no idea how to solve.
I found a MS help website that walked me through how to create a UserForm using VBA code. It said to first click tools > references > check MS VBA Extensibility. I then copy and pasted their sample code, but it gave me the error: Run-time error '1004': Application-defined or object-defined error. I then went back to references and saw that MS VBA Extensibility's location is given as C:\Program Files (x86)\Common Files\Microsoft Shared\VBA. I went into the MS Shared folder, but didn't find VBA, so I copied it to my computer from another computer in my office. That did not fix the problem. I am wondering if I may be missing files? The only folder inside VBA is VBA6 which contains only VBE6EXT.OLB. I have tried running code that claims to create a UserForm, but I keep getting the same error. Here is an example of the code I have tried using.
Sub Add_Form1()
' Declare a variable to hold the UserForm.
Dim x As Object
' Create a new UserForm. You can use this new VBComponent object
' to manipulate the User Form.
Set x = Application.VBE.ActiveVBProject.VBComponents.Add _
(vbext_ct_MSForm)
End Sub
My error is on the line Set x = Application.VBE.....
When I manually type in the code, VBA recognizes everything I am typing in (it will give me autofill options), so I am stumped as to why this code won't work for me.
Bookmarks