Application Error when running Macro on Workbook open

T

TM

I have a multipage form that I'd like to open when a
workbook is opened. It reads values from various defined
Names of the workbook to populate the form fields. The
user can then change the values and on pressing 'OK'
button the values should be validated and if appropriate
re-copied back into the cells referenced by the Names.
This works fine when I display the form from the already
opened workbook, but the process fails with Error 1004
("Application-defined or object-defined error") when the
form is called from the Workbook_Open() procedure. The
procedure crashes on the following line:

ActiveWorkbook.Names(arrControlNames(intCurrentControl,
2)).RefersToRange.Value = _
Controls(arrControlNames(intCurrentControl, 1)).Value

Where arrControlNames is an array to store details of text
controls and associated name such that
arrControlNames(x,1) is the ControlName
and arrControlNames(x,2) is the associated RangeName


Full code extract is below.

Can anyone shed any light on this?

Thanks in advance

TM

==================
Private Sub Workbook_Open()
Load frmProjectProperties
frmProjectProperties.Show
End Sub

Private Sub cmdOK_Click()
'First, validate all values - if invalid then exit sub
'... {Validation Code}
'...


'If we reach this point then all values have tested
valid
'Update values to worksheet and close form
For intCurrentControl = LBound(arrControlNames, 1) To
UBound(arrControlNames, 1)
If arrControlNames(intCurrentControl, 1) <> "" Then
ActiveWorkbook.Names(arrControlNames
(intCurrentControl, 2)).RefersToRange.Value = _
Controls(arrControlNames
(intCurrentControl, 1)).Value
End If
Next


Unload frmProjectProperties

End Sub
 
T

TM

Oops wrong forum, this belongs under Excel sorry :-/

PS If anyone knows the answer, I'm about to re-post under
Excel,Programming...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top