PDA

View Full Version : Solved: An User Definied Function Can do?



Erdin? E. Ka
09-24-2006, 07:58 AM
Hi there,

An U.D.F. can start/run an event or/and Macro?

I want to learn is it possible, and if it's ok, can anybody tell me an easy sample?

For example;

Writing the UDF;


=FORMULA()


Then;

On Enter; "Example" Sub is running.


Sub Example()
MsgBox "Your Macro Is Running By UDF"
End Sub


Thanks a lot.

:hi:

mdmackillop
09-24-2006, 08:31 AM
Function test()
tryMsg
test = 4
End Function

Sub tryMsg()
MsgBox "UDF in use"
End Sub

Erdin? E. Ka
09-24-2006, 09:04 AM
Hi dear mdmackillop,
Well done!
Thank you.:hi:

Erdin? E. Ka
09-25-2006, 12:19 PM
Hi again,

I wrote into D1 cell as =FORMULA()

depended the codes below but returned #VALUE and a MsgBox as "That Function is not valid".

( C:\Image1 ist ok. I have that file in C drive. )

Function FORMULA()
AddPicture
FORMULA = "UDF in Use."
End Function

Sub AddPicture()
ActiveSheet.Pictures.Insert("C:\Image1").Select
End Sub

I can't understand where i am wrong! :dunno

Please help me. :help

mdmackillop
09-25-2006, 12:40 PM
You cannot use a UDF to change other cells on a worksheet.

Erdin? E. Ka
09-25-2006, 01:04 PM
Ok, isee.

Probably i should use an another way.:yes

Thank you.