Fun with VBScript and Macro Sheduler

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Fun with VBScript and Macro Sheduler

Post by edauthier » Fri Aug 17, 2007 2:18 pm

Here's a nice piece of VBScript to run with Macro. You could run without Macro Scheduler, but why would you want to.

The script calls the Microsoft .acs agent 'Merlin' who will appear on screen with a little animation and some messages.

It can help anyone looking to learn VBS, simply due to each step and perfomance of the script.

Have fun .. and turn your volume down if you're at work it plays sounds.

Ed



VBSTART
Option Explicit



Const Complete = 0, Pending = 2



Dim objAgent, objChar, objRequest, txtSpeak
Dim strCharacter, Shell, strFirstName



strFirstName = "MS Forum Friend"
strCharacter = "Merlin"
'strCharacter = "Genie"



Set Shell = CreateObject("WScript.Shell")

If HaveAgent() Then


objAgent.Characters.Load strCharacter, strCharacter & ".acs"
Set objChar = objAgent.Characters(strCharacter)
With objChar
.Top = 50
.Left = 50
.LanguageID = &h409
.Show
End With

objChar.Play "Greet"
objChar.Speak "Hello, " & strFirstName & "\Vol=100"
objChar.Play "GetAttention"
objChar.Play "GetAttentionReturn"
objChar.Speak "Hello! " & strFirstName
objChar.Play "Idle2_2"
objChar.Play "Acknowledge"
objChar.Play "Announce"
objChar.Speak "Reviewing the code may help you with VBScripting"
objChar.MoveTo 800, 600
objChar.Play "Idle3_1"
objChar.Play "Wave"
objChar.Speak "Goodbye and happy Scripting!" & strFirstName



Set objRequest = objChar.Hide
Do Until objRequest.Status = Complete
Wscript.Sleep 100
Loop

Set objChar = Nothing
objAgent.Characters.Unload strCharacter

WScript.Quit
Else



Shell.Popup "MS Agent NOT Found !" & vbCrLf, _
10, _
"Error Message", _
vbInformation + vbOKOnly + vbSystemModal
Wscript.Quit
End If

Function HaveAgent()



HaveAgent = False
On Error Resume Next
Set objAgent = CreateObject("Agent.Control.1")
objAgent.Connected = True
HaveAgent = IsObject(objAgent)
End Function


VBEND

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Aug 17, 2007 3:58 pm

This doesn't actually work from within Macro Scheduler as is because it needs to use the WSH sleep function which is not available to Macro Scheduler. You'd have to run this natively.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Post by edauthier » Fri Aug 17, 2007 4:03 pm

AH.. I see what you are saying. It runs under my XP and Vista from within MS, however, with the WSH error. ( which is harmless).
Anyway...

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Aug 17, 2007 4:11 pm

Workaround:

Code: Select all

VBSTART
Option Explicit
Const Complete = 0, Pending = 2
Dim objAgent

Sub DoWizard(tmpscp)

  Dim objChar, objRequest, txtSpeak
  Dim strCharacter, Shell, strFirstName

  strFirstName = "Macro Scheduler User"
  strCharacter = "Merlin"
  'strCharacter = "Genie"
  Set Shell = CreateObject("WScript.Shell")

  If HaveAgent() Then

    objAgent.Characters.Load strCharacter, strCharacter & ".acs"
    Set objChar = objAgent.Characters(strCharacter)
    With objChar
    .Top = 50
    .Left = 50
    .LanguageID = &h409
    .Show
    End With

    objChar.Play "Greet"
    objChar.Speak "Hello, " & strFirstName & "\Vol=100"
    objChar.Play "GetAttention"
    objChar.Play "GetAttentionReturn"
    objChar.Speak "Hello! " & strFirstName
    objChar.Play "Idle2_2"
    objChar.Play "Acknowledge"
    objChar.Play "Announce"
    objChar.Speak "This EXE was built with Macro Scheduler"
    objChar.MoveTo 800, 600
    objChar.Play "Idle3_1"
    objChar.Play "Wave"
    objChar.Speak "Goodbye and happy Scripting " & strFirstName & "!"


    Set objRequest = objChar.Hide
    Do Until objRequest.Status = Complete
       Call Shell.Run (tmpscp, ,true)
    Loop

    Set objChar = Nothing
    objAgent.Characters.Unload strCharacter
	'Shell.Quit

  Else
    Shell.Popup "MS Agent NOT Found !" & vbCrLf, _
    10, _
    "Error Message", _
    vbInformation + vbOKOnly + vbSystemModal
    'Shell.Quit
    End If
End Sub

Function HaveAgent()
  HaveAgent = False
  On Error Resume Next
  Set objAgent = CreateObject("Agent.Control.1")
  objAgent.Connected = True
  HaveAgent = IsObject(objAgent)
End Function

VBEND

WriteLn>%TEMP_DIR%\sleep.vbs,r,WScript.sleep 100
VBRun>DoWizard,%TEMP_DIR%\sleep.vbs
DeleteFile>%TEMP_DIR%\sleep.vbs
Here's the compiled EXE (in a zip file):
http://www.mjtnet.com/software/merlin.zip
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

edauthier
Pro Scripter
Posts: 84
Joined: Sun Apr 13, 2003 1:26 pm
Location: USA

Post by edauthier » Sun Aug 19, 2007 12:19 am

There are other characters besides Merlin: Genie, Reedy and Robby. You can download the others here from Microsoft.

http://www.microsoft.com/msagent/downlo ... #character

Below are some extra Merlin movements for your macro script. Let the forum know if you do something really clever with Macro Scheduler and your MS Agent.

Enjoy. Ed

Code: Select all

 Acknowledge
  Announce
  Blink
  Congratulate
  DoMagic1
  DoMagic2
  Explain
  GestureDown
  GestureLeft
  GestureRight
  GetAttention
  LookUpBlink
  MoveDown
  MoveLeft
  MoveRight
  MoveUp
  Pleased
  Process
  Read
  Sad
  Search
  Show
  Think
  Wave
  Write

plywoodca
Newbie
Posts: 3
Joined: Fri Jan 04, 2008 5:22 pm

Post by plywoodca » Fri Jan 04, 2008 5:38 pm

I copied and pasted the workaround, but when executing it a Notepad window opens, the script runs, but the macro does not end until I close the Notepad window. Is there a way around having to do this?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts