CodeMonkey01
New Member
- Joined
- Jul 21, 2011
- Messages
- 6
A colleague and I are building a template builder, which reads data from an XML, opens a new workbook, imports a number of pre-coded modules and userform(s), then dynamically adds buttons and labels to the userform, complete with event handlers. We've gotten 99% of it to work, but we cannot name our dynamically-created controls. For instance:
The compiler blows up on the .name line with this message:
Run-time error '40044':
Could not set the Name property. Could not complete the operation due to error 800a9c6c.
Google has failed me in regard to that error number (800a9c6c). Thus far, I have been unable to use ufMain.Controls(lblHeading.Name).Properties("Name") = TextString, either, as the compiler says the object doesn't support this property or method.
Does anyone know how I can set a name for my controls that are created this way? We've determined workarounds for this, but it's going to be a big pain and may not work in the future; this project builder is intended to be available to non-programmers who can edit an XML in the future.
I am working in Excel 2007.
Thank you in advance for any assistance.
Code:
With wbProject.VBProject.VBComponents
'--Load the list of nodes we want to loop through
Set ufMain = .Item("ufMain")
Set frmSummary = ufMain.Designer.Controls.Item("frmSummary")
Set xmlNodeList = JOBXML.SelectNodes("/JobProcessingInstructions/LoanHeaders/LoanHeader")
For Each xmlNode In xmlNodeList
'--Retrieve the label value from the xml
strLoanHeader = xmlNode.Attributes.getNamedItem("Value").nodeTypedValue
Set lblHeading = frmSummary.Controls.Add("Forms.Label.1") ', "lbl" & strLoanHeader & "Heading")
With lblHeading
.Name = "lbl" & strLoanHeader & "Heading"
.Top = 12 + (iRows * 18)
The compiler blows up on the .name line with this message:
Run-time error '40044':
Could not set the Name property. Could not complete the operation due to error 800a9c6c.
Google has failed me in regard to that error number (800a9c6c). Thus far, I have been unable to use ufMain.Controls(lblHeading.Name).Properties("Name") = TextString, either, as the compiler says the object doesn't support this property or method.
Does anyone know how I can set a name for my controls that are created this way? We've determined workarounds for this, but it's going to be a big pain and may not work in the future; this project builder is intended to be available to non-programmers who can edit an XML in the future.
I am working in Excel 2007.
Thank you in advance for any assistance.