Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Pass a Function Value thru several Subs

I currently have a toolbar that has 4 Controls:

Control1 - Sorts Data
Control2 - Prints Data
Control3 - Copies Data to Other Worksheets
Control4 - Prints those Worksheets.

If Control1 is fired it will sort the data and use a MsgBox to ask the user
if they want to print. If Control2 is fired it will sort the data and bypass
the MsgBox, because the user has already demanded to print.

Sub Control1Macro(Optional ByVal StopCode As Boolean)

' sort data on data worksheet

' if StopCode = False ask to print, if print automatically
If StopCode = False Then
' ask if user wants to print
strPrompt = "The Ready Schedule has been produced, would you like to
print?"
intButtons = vbYesNo + vbQuestion
strTitle = "Ready Schedule"
If MsgBox(strPrompt, intButtons, strTitle) = vbYes Then
Application.Dialogs(xlDialogPrint).Show
End If
Else
Application.Dialogs(xlDialogPrint).Show
End If
End Sub

Public Sub PrintReadySchedule()
Call ReadySchedule(True)
End Sub

Control3 and Control4 relate a little differently. Here is my question.
How do I pass the StopCode Value from Control3 to Control4? This is the
procedure setup:

Sub Control3Macro(Optional ByVal StopCode As Boolean)
' Activate UserForm1 (Userform1 is a make shift progress bar)
End Sub

Sub Activate_Userform()
Call CompileSchedules
End Sub

Sub CompileSchedules()
' Copies Data to Other Worksheets
' makes updates to userform while compiling

If StopCode = False then
' Ask User to Print
Else
' print those worksheets
End If

End Sub

Sub Control4Macro()
Call Control3Macro(True)
End Sub


Thanks in Advance!!
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Pass a Function Value thru several Subs

Hi
Make Stopcode a public Variable in one of two ways
1. If all your subs are in one code module then put this at the top of
the code module outside any sub. Do not declare it in any sub or its
value will be overwritten.
Dim StopCode as Boolean

2. If your subs are in different code modules then put this at the top
of the code module outside any sub. Do not declare it in any sub or
its value will be overwritten.
Public StopCode as Boolean

This variable will last as long as Excel is open. Note that any code
error will destroy the value of a public variable.
regards
Paul

On Oct 2, 8:14*pm, RyanH wrote:
I currently have a toolbar that has 4 Controls:

Control1 - Sorts Data
Control2 - Prints Data
Control3 - Copies Data to Other Worksheets
Control4 - Prints those Worksheets.

If Control1 is fired it will sort the data and use a MsgBox to ask the user
if they want to print. *If Control2 is fired it will sort the data and bypass
the MsgBox, because the user has already demanded to print.

Sub Control1Macro(Optional ByVal StopCode As Boolean)

* *' sort data on data worksheet

* * ' if StopCode = False ask to print, if print automatically
* * If StopCode = False Then
* * * * ' ask if user wants to print
* * * * strPrompt = "The Ready Schedule has been produced, would you like to
print?"
* * * * intButtons = vbYesNo + vbQuestion
* * * * strTitle = "Ready Schedule"
* * * * If MsgBox(strPrompt, intButtons, strTitle) = vbYes Then
* * * * * * Application.Dialogs(xlDialogPrint).Show
* * * * End If
* * Else
* * * * Application.Dialogs(xlDialogPrint).Show
* * End If
End Sub

Public Sub PrintReadySchedule()
* * Call ReadySchedule(True)
End Sub

Control3 and Control4 relate a little differently. *Here is my question.. *
How do I pass the StopCode Value from Control3 to Control4? *This is the
procedure setup:

Sub Control3Macro(Optional ByVal StopCode As Boolean)
* *' Activate UserForm1 (Userform1 is a make shift progress bar)
End Sub

Sub Activate_Userform()
* *Call CompileSchedules
End Sub

Sub CompileSchedules()
* *' Copies Data to Other Worksheets
* *' makes updates to userform while compiling

* *If StopCode = False then
* * * ' *Ask User to Print
* *Else
* * * ' print those worksheets
* *End If

End Sub

Sub Control4Macro()
* *Call Control3Macro(True)
End Sub

Thanks in Advance!!
--
Cheers,
Ryan


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
Pass the variable into the sub function Richard Excel Programming 4 December 28th 06 10:58 AM
pass workbook on to function? Sonnich Excel Programming 1 May 18th 06 01:41 PM
Pass function as argument to UDF Ron Rosenfeld Excel Programming 10 February 9th 06 12:48 PM
Defining Variables that pass to other Subs JasonSelf[_14_] Excel Programming 2 August 11th 04 08:57 PM


All times are GMT +1. The time now is 09:35 PM.

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"