VBSCRIPT SAVEAS

3.1k views Asked by At

I have the following:

set wshshell=createobject("wscript.shell")
wshshell.run """C:\ReportName.pdf"""

This opens the named PDF. What code do I need to save that opened file as, like a SaveAs.. saving it as the same filename?

Thanks

2

There are 2 answers

2
Pankaj Jaju On BEST ANSWER

Here is sample code

set wshshell=createobject("wscript.shell")
wshshell.run """C:\ReportName.pdf"""
wscript.sleep 2000 'sleep for 2 seconds to ensure file is open
wshshell.SendKeys "%{F}{A}" 'simulate ALT+F+A to open SaveAs dialog
wscript.sleep 5000 ' sleep for 5 seconds so that the save as dialog is open
wshshell.SendKeys "+{TAB}{ENTER}" 'simulate Shit+Tab so that the tab is moved backed to Choose a diff folder option
wscript.sleep 2000
wshshell.SendKeys "C:\NewFile.PDF{ENTER}"
wscript.sleep 3000
wshshell.SendKeys "%{F}{X}"
0
Helen On

It sounds like you want to copy the file or move/rename the file. If so, use FileSystemObject:

Set fso = CreateObject("Scripting.FileSystemObject")
Call fso.CopyFile("C:\ReportName.pdf", "C:\NewReport.pdf")
' or
Call fso.MoveFile("C:\ReportName.pdf", "C:\NewReport.pdf")