how to determine if a reference is selected and set it if it is no

M

MikeB77

I'm trying to programatically test if the Microsoft Speech Object Library is
selected and then if it is not I'd like to set it.

I've tried error trapping each side of a Dim but that didn't work:
On error reume next
Voc = SpeechLib.SpVoice
On error resume 0
If voc is nothing then '... let me know or fix it

Due to security levels I hope I can do this without
Application.VBE.ActiveVBProject.References

Can anyone shine some light on this one?

Thanks!
Mike
 
J

Jonathan West

MikeB77 said:
I'm trying to programatically test if the Microsoft Speech Object Library
is
selected and then if it is not I'd like to set it.

I've tried error trapping each side of a Dim but that didn't work:
On error reume next
Voc = SpeechLib.SpVoice
On error resume 0
If voc is nothing then '... let me know or fix it

Due to security levels I hope I can do this without
Application.VBE.ActiveVBProject.References

Can anyone shine some light on this one?


Use late binding instead. In other words, use GetObject or CreateObject to
assign the object to a variable declared as an Object.

Then if the CreateObject call fails (i.e. the object is Nothing after the
call) you can act accordingly.
 
M

MikeB77

Thanks for your assistance. I should have thought of that.
But when I try:
set voc = CreateObject("SpeechLib.SpVoice") or
Set Voc = CreateObject("SpVoice")
or similar I get error 429: ActiveX can't create object. I've read that
ActiveX components can't create user defined funcitons
(http://support.microsoft.com/kb/184898). So am I going about this the wrong
way?

Thanks
Mike
 
S

Steve Yandl

Mike,

This may be a different object but what I use from vbScript also works in
VBA routines. See if you can make this do what you want.

strText = "This is a test"
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.Speak strText


Steve
 
M

MikeB77

Thanks Steve. That may be a different object, or just a easier way to SAPI:
either way its got it nailed. No setting references required!

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top