Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Call a procedure in the workbook from a worksheet

I am using Excel 2000.
I create a button in a worksheet. On clicking this button, I like a
procedure "Main" in the workbook that contains the worksheet to run.
What is wrong with the following code in the worksheet ? When I click the
button, I obtain Run-time error '1004', Application-defined or object-defined
error.
Private Sub BtnRetrieve_Click()
ThisWorkbook.Main
MsgBox "End"
End Sub

For ThisWorkbook, I have
Option Explicit
Dim QtrData as string
Sub Main()
many VBA statements ....
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Call a procedure in the workbook from a worksheet

It sounds like you have an error in the Main procedure. Run it from the VBE
and see where it errors.

BTW, probably not a good idea to put general code in ThisWorkbook, better in
a normal code module.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Selina" wrote in message
...
I am using Excel 2000.
I create a button in a worksheet. On clicking this button, I like a
procedure "Main" in the workbook that contains the worksheet to run.
What is wrong with the following code in the worksheet ? When I click the
button, I obtain Run-time error '1004', Application-defined or

object-defined
error.
Private Sub BtnRetrieve_Click()
ThisWorkbook.Main
MsgBox "End"
End Sub

For ThisWorkbook, I have
Option Explicit
Dim QtrData as string
Sub Main()
many VBA statements ....
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Call a procedure in the workbook from a worksheet

Try declaring it as:

Public Sub Main()
many VBA statements ....
End Sub

--
Regards,
Tom Ogilvy

"Selina" wrote in message
...
I am using Excel 2000.
I create a button in a worksheet. On clicking this button, I like a
procedure "Main" in the workbook that contains the worksheet to run.
What is wrong with the following code in the worksheet ? When I click the
button, I obtain Run-time error '1004', Application-defined or

object-defined
error.
Private Sub BtnRetrieve_Click()
ThisWorkbook.Main
MsgBox "End"
End Sub

For ThisWorkbook, I have
Option Explicit
Dim QtrData as string
Sub Main()
many VBA statements ....
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Call a procedure in the workbook from a worksheet


is your main stored in thisworkbook code module?
NOT a good idea.
insert a normal module and put your code there.





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Selina wrote :

I am using Excel 2000.
I create a button in a worksheet. On clicking this button, I like a
procedure "Main" in the workbook that contains the worksheet to run.
What is wrong with the following code in the worksheet ? When I
click the button, I obtain Run-time error '1004', Application-defined
or object-defined error.
Private Sub BtnRetrieve_Click()
ThisWorkbook.Main
MsgBox "End"
End Sub

For ThisWorkbook, I have
Option Explicit
Dim QtrData as string
Sub Main()
many VBA statements ....
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
to call procedure in a worksheet in a module CAPTGNVR Excel Discussion (Misc queries) 4 January 30th 07 09:39 PM
Call Procedure Ronbo Excel Programming 4 February 23rd 05 08:11 PM
Where else to look for procedure call Lulu Excel Programming 0 November 24th 04 03:07 PM
Where else to look for procedure call Lulu Excel Programming 2 November 24th 04 02:14 AM
procedure won't call John Gittins Excel Programming 0 August 5th 03 08:17 PM


All times are GMT +1. The time now is 04:54 PM.

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

About Us

"It's about Microsoft Excel"