View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default How to run a shell command via VBA?

Untested. (I don't have that printer or that script.)

dim myFileName as string
dim myParms as string

myfilename = "Cscript"
myparms = "%windir%\system32\prnmngr.vbs -ac -p ""\\rds1\Printer088""

Shell Environ("comspec") _
& " /k " & Chr(34) & myFileName & Chr(34) & " " & myparms, vbNormalFocus


Use /c says to close that (hidden!) window when it's done.
The /k to see the command window (/k = keep open).

And when you're done testing, you may want vbHide so the window isn't
noticeable. (See VBA's help for Shell to see the options.)

If this doesn't work (or some variation), you may want to include the version of
windows that you're running. I'm not sure all still support Shell.


Benjamin wrote:

I want to run shell commands via VBA?
particularly this one:

Which adds a printer default
CSCRIPT %windir%\system32\prnmngr.vbs -ac -p "\\rds1\Printer088"


--

Dave Peterson