VBScript rookie problems |
Post Reply |
Author | |
russ
Member Joined: 17/Jan/2009 Status: Offline Points: 71 |
Post Options
Thanks(0)
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 SendKeys "^o",1 'open the mail message Set msg = ActiveInspector.CurrentItem SendKeys "%{F4}" 'close the mail message ShellExecute attachmentname, 1, "", "Attachment" 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> Set objOutlook = GetObject(, "Outlook.Application") Application.SendKeys("{{CTRL}}o") 'open the mail message msg = objOutlook.ActiveInspector.CurrentItem Application.SendKeys("{{ALT}}{F4}") 'close the mail message ShellExecute attachmentname, 1, "", "Attachment" 'need to find VBScript command equivalent |
|
antihadron
Member Joined: 27/Feb/2009 Status: Offline Points: 18 |
Post Options
Thanks(0)
|
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 |
|
russ
Member Joined: 17/Jan/2009 Status: Offline Points: 71 |
Post Options
Thanks(0)
|
Nataniel,
Thanks for showing the way for me. I appreciate it!
-Russ
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |