Shred Dude
03-02-2011, 03:02 PM
I've developed a .dotm file that contains Ribbon buttons that launch user forms, etc.
When I have this file open, as when editing, it works flawlessly for me. When I move a copy of it to my Startup Folder and have it launched automatically as an Add-In (Global Template), everything works fine, except the launch of one user form. I"m stumped.
The code below is from the UserForm's Initialization sub, and it works fine when .dotm file is open, but not when installed as a global template. When using with the template open, the userform pops up and all six fields are accurately populated. When run from the template when installed as a Global Template, it fails if the last two lines are not commented out. That is, it will work with those lines commented out, populating the first four text boxes. If those two lines are not commented out, it throws a VBA error 5, Invalid Procedure Call or Argument. It doesn't get to my error handling code.
Private Sub UserForm_Initialize()
'fill Text boxes with Custom Document Properties
On Error GoTo errhandler
With ThisDocument
Me.txtConTemplate.Text = .CustomDocumentProperties("Bulletin Agreement Template").Value
Me.txtContractsFolder.Text = .CustomDocumentProperties("Contracts Folder").Value
Me.txtPanelData.Text = .CustomDocumentProperties("Panel Data").Value
Me.txtReportsFolder.Text = .CustomDocumentProperties("Reports Folder").Value
'When Global Template, if these lines active, code fails with VBA Erro 5
'Invalid Procedure Call or Argument. WHAT'S CAUSING THIS????
'if I comment out two lines below, fomr opens with first four fields populated
'if run when Template Open, code executes fine...populating all six fields
Me.txtConEmail.Text = .CustomDocumentProperties("Contract Email").Value
Me.txtSalesRep.Text = .CustomDocumentProperties("Sales Rep").Value
End With
Me.Caption = "Testing"
errExit:
Exit Sub
errhandler:
MsgBox "Set Up User Form Initializaton failed" & vbCr & _
Err.Number & " - " & Err.Description, vbCritical, "ERROR"
Err.Clear
Resume errExit
End Sub
Any ideas? I'm stumped. Have gone through line by line commenting out the calls to the custom document properties and concluded it works fine if the email and sales rep are commented out but not otherwise. Works fine when template is opened and then run though. ??????
When I have this file open, as when editing, it works flawlessly for me. When I move a copy of it to my Startup Folder and have it launched automatically as an Add-In (Global Template), everything works fine, except the launch of one user form. I"m stumped.
The code below is from the UserForm's Initialization sub, and it works fine when .dotm file is open, but not when installed as a global template. When using with the template open, the userform pops up and all six fields are accurately populated. When run from the template when installed as a Global Template, it fails if the last two lines are not commented out. That is, it will work with those lines commented out, populating the first four text boxes. If those two lines are not commented out, it throws a VBA error 5, Invalid Procedure Call or Argument. It doesn't get to my error handling code.
Private Sub UserForm_Initialize()
'fill Text boxes with Custom Document Properties
On Error GoTo errhandler
With ThisDocument
Me.txtConTemplate.Text = .CustomDocumentProperties("Bulletin Agreement Template").Value
Me.txtContractsFolder.Text = .CustomDocumentProperties("Contracts Folder").Value
Me.txtPanelData.Text = .CustomDocumentProperties("Panel Data").Value
Me.txtReportsFolder.Text = .CustomDocumentProperties("Reports Folder").Value
'When Global Template, if these lines active, code fails with VBA Erro 5
'Invalid Procedure Call or Argument. WHAT'S CAUSING THIS????
'if I comment out two lines below, fomr opens with first four fields populated
'if run when Template Open, code executes fine...populating all six fields
Me.txtConEmail.Text = .CustomDocumentProperties("Contract Email").Value
Me.txtSalesRep.Text = .CustomDocumentProperties("Sales Rep").Value
End With
Me.Caption = "Testing"
errExit:
Exit Sub
errhandler:
MsgBox "Set Up User Form Initializaton failed" & vbCr & _
Err.Number & " - " & Err.Description, vbCritical, "ERROR"
Err.Clear
Resume errExit
End Sub
Any ideas? I'm stumped. Have gone through line by line commenting out the calls to the custom document properties and concluded it works fine if the email and sales rep are commented out but not otherwise. Works fine when template is opened and then run though. ??????