Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Application Error when running Macro on Workbook open

I posted this a couple of weeks ago but got no response.
So in a spirit of perseverance (optimism even ;-)) here we
go again...

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(intCurrentCon trol,
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Application Error when running Macro on Workbook open

Hi,

I would suggest to move your code that shows the form out
of the Thisworkbook module, like this:


Private Sub Workbook_Open()
Application.OnTime Now,"ShowYourForm"
End Sub

And in a normal module:

Sub ShowYourForm()
Load frmProjectProperties
frmProjectProperties.Show
End Sub

Regards,

Jan Karel Pieterse
Excel TA/MVP

-----Original Message-----
I posted this a couple of weeks ago but got no response.
So in a spirit of perseverance (optimism even ;-)) here

we
go again...

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(intCurrentCo ntrol,
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

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro error when trying to open workbook paankadu Excel Worksheet Functions 6 November 6th 09 03:54 PM
Running a macro from windows application Aerojade Excel Discussion (Misc queries) 1 October 3rd 08 01:19 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
Open Application Error? Emile Ianni Setting up and Configuration of Excel 1 October 12th 05 03:34 PM
Application Error when running Macro on Workbook open TM[_2_] Excel Programming 0 September 15th 03 12:33 PM


All times are GMT +1. The time now is 12:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"