Wrox Programmer Forums
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 5th, 2003, 12:38 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default SendKey commands

I'm am using SendKey commands in Excel. But cannot get them to work as they should.
 Set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.Run "Excel"
 WScript.Sleep 500
 WshShell.AppActivate "Microsoft Excel"
 WshShell.SendKeys "%+(t)"
 WScript.Sleep 250
 WshShell.SendKeys "m"
 WScript.Sleep 250
 WshShell.SendKeys "~"
 WScript.Sleep 250
 WshShell.SendKeys "~"

I'm using this little bit of script to open Excel and then go to the Macro command and run the first macro
Excep where I have WshShell.SendKeys "%+(t)" I tried using the Excel hot key to run the Macro Alt+F8 WshShell.SendKeys "^{F8}", but that didn't work. Then I tried the the Excel command to open the menu bar and go to "T" for tools then down to "M" for macro. Alt+T M. or WshShell.SendKeys "^{T}"
WScript.Sleep 250
 WshShell.SendKeys "m"

That doesn't work either

Why can't I use SendKeys with the Excel hotkeys?


Charlie3
[email protected]
Reply With Quote
  #2 (permalink)  
Old July 6th, 2003, 02:30 PM
Authorized User
 
Join Date: Jul 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default

Hi Charlie, try this method as it'll be more efficient & you won't have to rely on sendkeys: :)
Code:
Dim objXLApp
Set objXLApp = CreateObject("Excel.Application")

objXLApp.Workbooks.Open "C:\Book1.xls"
objXLApp.visible = true
objXLApp.DisplayAlerts = False

objXLApp.Run "Book1.xls!Macro1"

objXLApp.Workbooks(1).Save
objXLApp.Workbooks(1).Close
objXLApp.DisplayAlerts = True
objXLApp.Quit
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Python's commands: Help Static Python 3 March 26th, 2015 12:34 AM
ABOUT AT COMMANDS bobwith5 Visual Basic 2005 Basics 1 October 31st, 2007 02:25 PM
sql commands dr BOOK: Beginning Ruby on Rails 1 April 27th, 2007 12:22 PM
Sendkey not working kimb Excel VBA 3 March 14th, 2006 06:58 PM
Using 2 SQL commands attipa Classic ASP Databases 2 September 20th, 2003 05:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.