Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Return codes from called macros


I have my main macro that calls another macro via Application.Ru
"Called Macro".

Within the called macro I attempt to have the user open a file so i
can be processed. If the user selects cancel when prompted & doesn'
open the file, I exit the called macro. But now I want my main macro t
know that this just happened so I can exit it also.

How do I pass return codes back from a called macro to the main macro
reference the return code in the main macro

--
mwc091
-----------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...fo&userid=2413
View this thread: http://www.excelforum.com/showthread.php?threadid=55857

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Return codes from called macros

Make the macro a function, and return a status code from that function. To
call it, use

rtn = Application.Run("'wkb'!myFunc")

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"mwc0914" wrote in
message ...

I have my main macro that calls another macro via Application.Run
"Called Macro".

Within the called macro I attempt to have the user open a file so it
can be processed. If the user selects cancel when prompted & doesn't
open the file, I exit the called macro. But now I want my main macro to
know that this just happened so I can exit it also.

How do I pass return codes back from a called macro to the main macro &
reference the return code in the main macro?


--
mwc0914
------------------------------------------------------------------------
mwc0914's Profile:

http://www.excelforum.com/member.php...o&userid=24130
View this thread: http://www.excelforum.com/showthread...hreadid=558576



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Return codes from called macros


Set up your called macro as a function. The example below calls a function
named 'CalledMacro', which returns either a string containing the selected
filename or a null string (if the user canceled out of the File Open dialog).

Sub TEST()
Dim FileToOpen As String
FileToOpen$ = CalledMacro
If FileToOpen$ = vbNullString Then Exit Sub
'Otherwise, open the selected workbook.
Workbooks.Open Filename:=FileToOpen$
End Sub

Function CalledMacro() As String
Dim Fyle As String
Fyle1$ = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If Fyle1$ = "False" Then
CalledMacro = vbNullString
Else
CalledMacro = Fyle1$
Exit Function
End Function

Hope this helps,

Hutch
------------------------------
"mwc0914" wrote:


I have my main macro that calls another macro via Application.Run
"Called Macro".

Within the called macro I attempt to have the user open a file so it
can be processed. If the user selects cancel when prompted & doesn't
open the file, I exit the called macro. But now I want my main macro to
know that this just happened so I can exit it also.

How do I pass return codes back from a called macro to the main macro &
reference the return code in the main macro?


--
mwc0914
------------------------------------------------------------------------
mwc0914's Profile: http://www.excelforum.com/member.php...o&userid=24130
View this thread: http://www.excelforum.com/showthread...hreadid=558576


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Return codes from called macros


Change your sub "Called Macro" to a function, then you can pass bac
results like in this example where main_macro calls called_macro an
receives the return value into a variable:

sub main_macro
dim TheResponse as string
TheResponse = called_macro()
msgbox TheResponse
end sub

function called_macro() as string
dim Answer as integer
Answer = msgbox("Yes or No?", vbyesno)
if Answer = vbyes then
called_macro = "Yes"
else
called_macro = "No"
endif
end function


Co

--
colofnatur
-----------------------------------------------------------------------
colofnature's Profile: http://www.excelforum.com/member.php...fo&userid=3435
View this thread: http://www.excelforum.com/showthread.php?threadid=55857

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
what is this called? : < Jake Excel Worksheet Functions 1 November 28th 06 11:01 AM
In macros, an instruction that will return the position of the Active Cell aca[_4_] Excel Programming 2 January 20th 06 10:50 PM
What are the character codes of a carriage return entered in a comment? John Wirt[_11_] Excel Programming 4 July 29th 05 06:05 AM
Carriage return in macros Manu Palao Excel Worksheet Functions 1 November 15th 04 01:57 PM
Carrying Variables into Called Macros Marty Excel Programming 2 June 12th 04 01:23 AM


All times are GMT +1. The time now is 12:37 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"