Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Call a Function


Hi all,

I can call a Macro like

'Call TestCode
or
'Run TestCode
or
TestCode
or use Select Case
etc

If i have a function named TestCode why can i not call it in this way?


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=522044

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Call a Function


Desert

You can call the function the same way unless you are expecting the
function to return data back to your macro or if you are passing
variable data onto the function

Sub Macro1()
call Function1
End Sub

Function MyFunction1()
function code here
End Function

or
Sub Macro2()
dim MyVariable As String
MyVariable = MyFunction2
End Sub

Function MyFunction2() as String
MyFunction2 = "Hi"
End Function

or

Sub Macro3()
dim MyVariable As Integer
MyVariable = MyFunction3(4)
End Sub

Function MyFunction3(iVariable As Integer) as Integer
MyFunction3 = iVariable + 6
End Function

or

If the function is on a worksheet module then you will need to use the
full sheet name as well as the function name

eg
call Sheet1.Function1


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=522044

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Call a Function

Hi Dave,

If i have a function named TestCode why can i not call it in this way?


You can. However, if the function returns a value, you may not observe any
response.

For demonstaryion purposes, I include a msgbox in the function:


Try:

'=============
Public Function ABC(aVal As Double)
ABC = aVal * 2
MsgBox ABC
End Function
'<<=============

'=============
Sub TestIt()
ABC (5)
Call ABC(100)
End Sub
'<<=============


---
Regards,
Norman



"Desert Piranha"
<Desert.Piranha.24n3vm_1142306702.1674@excelforu m-nospam.com wrote in
message news:Desert.Piranha.24n3vm_1142306702.1674@excelfo rum-nospam.com...

Hi all,

I can call a Macro like

'Call TestCode
or
'Run TestCode
or
TestCode
or use Select Case
etc

If i have a function named TestCode why can i not call it in this way?


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile:
http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=522044



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Call a Function


Hi Mudraker & Norman,

Thank You both for contributing to this.

This is over my head. Im quiting on this for now, as i can't seem to
work with it.
Its for personal use, and i have some stuff to do for work.
I will keep your stuff for future.

Thx again Norman and Mudraker


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=522044

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
Is there a do not call function? pokdbz Excel Discussion (Misc queries) 2 December 27th 07 04:00 PM
Call Sub from Function? G Lykos Excel Programming 1 November 23rd 05 06:48 AM
How do I call this function? vrk1 Excel Programming 1 June 18th 05 01:05 AM
call a function from VBA Adam Excel Programming 2 March 15th 05 10:17 AM
Function Call Phil Hageman Excel Programming 4 October 9th 03 04:32 PM


All times are GMT +1. The time now is 03:21 AM.

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"