Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple VBS question

Status
Not open for further replies.

lotaguts

Technical User
Mar 18, 2005
11
US
here is what I am trying to accomplish please look at code below.

Dim xlApp
Dim xlWkb
Set xlApp = CreateObject("excel.application")
Set xlWkb = xlApp.Workbooks.Open("\\myserver\sys\personal.xls")
Set xlWkb = xlApp.Workbooks.Open("\\myserver\sys\ReportExprenew.csv")
xlApp.Visible = True
Set xlWkb = Nothing
Set xlApp = Nothing

When the file ReportExprenew.csv opens I would like the Hotkeys "Ctrl Z" to be pressed how can accomplish this ?

Thanks for any feedback
 
Use the sendkeys function. Do some searching and you will find it around many times.
 
how about this: (just an example)
Code:
Set WSHShell = WScript.CreateObject("Wscript.Shell") 
WSHShell.Run ("notepad.exe")
WshShell.AppActivate ("untitled - notepad")
WScript.Sleep 500
wshshell.sendkeys "^Z"
you have to "activate" (focus)
and then send keys to the app.
 
How would I apply this to my script which opens a csv in excel ? thanks again
 
I would try this:

When you have your excel sheet open, note the "title" of the app in the taskbar. Lets just say its "myspreadsheet.xls - Microsoft Excel". I would then try:

Code:
Set WSHShell = WScript.CreateObject("Wscript.Shell")
WshShell.AppActivate ("untitled - notepad")
WScript.Sleep 500
wshshell.sendkeys "^Z"
 
Dim xlApp
Dim xlWkb
Set xlApp = CreateObject("excel.application")
Set xlWkb = xlApp.Workbooks.Open("\\myserver\sys\personal.xls")
Set xlWkb = xlApp.Workbooks.Open("\\myserver\sys\ReportExpRenew.csv")
Set WSHShell = WScript.CreateObject("Wscript.Shell")
WshShell.AppActivate ("Microsoft Excel - ReportExpRenew.csv")
WScript.Sleep 500
wshshell.sendkeys "^Z"
xlApp.Visible = True
Set xlWkb = Nothing
Set xlApp = Nothing

Any ideas why the CTRL Z is being applied to personal.xls rather than ReportExpRenew.csv ? thanks for all your help
 
Correction ctrl z is not working at all am I using the correct syntax in the wshshell.sendkeys "^Z
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top