Print Page | Close Window

VBScript rookie problems

Printed From: MSSpeech-Forum
Category: Windows™ Speech Recognition Forums
Forum Name: Macros and Macro Development
Forum Description: WSR Macros, Tools, Files, and new Macro requests
URL: https://www.msspeech-forum.com/forum_posts.asp?TID=65
Printed Date: 23/Nov/2024 at 1:38pm
Software Version: Web Wiz Forums 12.02 - http://www.webwizforums.com


Topic: VBScript rookie problems
Posted By: russ
Subject: VBScript rookie problems
Date 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"/>




Replies:
Posted By: antihadron
Date 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




Posted By: russ
Date Posted: 01/Mar/2009 at 11:34am
Nataniel,
 
Thanks for showing the way for me. I appreciate it!
 
-Russ



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.02 - http://www.webwizforums.com
Copyright ©2001-2019 Web Wiz Ltd. - https://www.webwiz.net