MSSpeech-Forum Homepage
Forum Home Forum Home > Windows™ Speech Recognition Forums > Macros and Macro Development
  New Posts New Posts RSS Feed - VBScript rookie problems
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

VBScript rookie problems

 Post Reply Post Reply
Author
Message
russ View Drop Down
Member
Member


Joined: 17/Jan/2009
Status: Offline
Points: 71
Post Options Post Options   Thanks (0) Thanks(0)   Quote russ Quote  Post ReplyReply Direct Link To This Post Topic: VBScript rookie problems
    Posted: 21/Feb/2009 at 6:41pm

Hello,

I've been using Dragon NaturallySpeaking for a number of years now, and I recently started experimenting with WSR and its macro capability. I've managed to make a few XML-based macros with the help of Brad's extremely helpful "User's Guide," and over the last few days I've been trying to learn how to use VBScript within macros. I picked up a beginner's VBScript programming book at the library, read the first 100 pages, and thought I'd try modifying the following DNS command to work as a VBScript macro with WSR. The command opens an Outlook 2007 attachment by its number. I didn't write the command; I got it from another speech recognition forum and modified it to work the way I want it to. Here's the VBA code:

Sub Main
    Dim Att As Attachment
    Dim msg As MailItem
    Dim attachmentname As String

    SendKeys "^o",1  'open the mail message

    Set msg = ActiveInspector.CurrentItem
    Set Att = msg.Attachments.Item(CInt(ListVar1))
    attachmentname = Environ$("TEMP") + "/" + Att.FileName
    Att.SaveAsFile(attachmentname)

    SendKeys "%{F4}" 'close the mail message

    ShellExecute attachmentname, 1, "", "Attachment"
    Set msg=Nothing
    Set Att=Nothing
End Sub

I rewrote the code as shown below. The first problem I encountered was that my attempts (now commented out) to instantiate the WScript.Shell object resulted in the error, "Object required: WScript." It seems like a really basic command like that ought to work on my Vista Business system. Is there something else I'm supposed to install on my computer before I attempt to write, run, and debug VBScripts?

So I commented out the two WScript.Shell lines and kept going. (I later found out that I can use Application.SendKeys instead of the WshShell object's SendKeys statement, so maybe I won't need to instantiate this object anyway.) The next error I got was for the "msg = objOutlook.ActiveInspector.CurrentItem" line, as follows:

 Object doesn't support this property or method: 'msg'

Again, this statement seems pretty straightforward. I get the feeling like there's something missing that out to have installed first before I started trying to write VBScripts. Any advice? Thanks.

-Russ

<command>
<listenFor>open attachment [AttachNum]</listenFor>
<script language="VBScript"> 
<![CDATA[
Dim Att, msg, attachmentname, objWshObject, objOutlook

    Set objOutlook = GetObject(, "Outlook.Application")
    'Set objWshObject = GetObject(, "WScript.Shell")
    'Set objWshObject = WScript.CreateObject("WScript.Shell")

    Application.SendKeys("{{CTRL}}o") 'open the mail message

    msg = objOutlook.ActiveInspector.CurrentItem
    Att = objOutlook.msg.Attachments.Item(CInt({[AttachNum]}))
    attachmentname = objWshObject.ExpandEnvironmentStrings("TEMP") & "/" & Att.FileName
    Application.Att.SaveAsFile(attachmentname)

    Application.SendKeys("{{ALT}}{F4}")  'close the mail message

    ShellExecute attachmentname, 1, "", "Attachment" 'need to find VBScript command equivalent
    msg=Nothing
    Att=Nothing
]]>
</script>
</command>
<numbers name="AttachNum" start="1" stop="9"/>

Back to Top
antihadron View Drop Down
Member
Member


Joined: 27/Feb/2009
Status: Offline
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote antihadron Quote  Post ReplyReply Direct Link To This Post Posted: 27/Feb/2009 at 2:18am

You were trying to use the 'msg' attribute off of 'objOutlook' (does not exist).

 This should point you in the right direction. This displays the first attachment off of the first selected message.

Dim att2, msg, attachmentname, objWshObject, objOutlook,strFolderpath,strFile

 Set objOutlook = CreateObject("Outlook.Application")
    Set objWshObject = CreateObject("WScript.Shell")

'Pops up the 1st selected message can use ActiveInspecter.CurrentItem as well
    Set msg = objOutlook.ActiveExplorer.Selection.Item(1)
    msg.Display
'Saves attachment and launches according to file type registration...
'TODO-Use number passed in...
    msg.Attachments.Item(1).SaveAsFile "c:/Temp/" &  msg.Attachments.Item(1).FileName
    objWshObject.run("c:/Temp/" &  msg.Attachments.Item(1).FileName)
'Delete Item when done?   


Hope this helps,

Nathaniel
http://www.thevoicesoftware.com


Back to Top
russ View Drop Down
Member
Member


Joined: 17/Jan/2009
Status: Offline
Points: 71
Post Options Post Options   Thanks (0) Thanks(0)   Quote russ Quote  Post ReplyReply Direct Link To This Post Posted: 01/Mar/2009 at 11:34am
Nataniel,
 
Thanks for showing the way for me. I appreciate it!
 
-Russ
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.02
Copyright ©2001-2019 Web Wiz Ltd.

This page was generated in 0.281 seconds.

Microsoft Most Valuable Professional

§- Thank you for visiting our Windows Speech Recognition and Macro Forum.. -§