Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vbs file to print a file from a directory

72 views
Skip to first unread message

Chris Peel

unread,
Feb 5, 2001, 11:44:23 PM2/5/01
to
Does anyone have sample code that simple takes a file and prints it... like right clicking in the directory and selecting print.  What I really want to do is print all the files in a directory via vbs file - saving me the time and effort of selecting the files.
 
Any sample code would help... save me the time of digging through the documentation.  Thanks
 
Chris
 

Michael Harris

unread,
Feb 6, 2001, 12:05:32 AM2/6/01
to
A version of Windows with "Active Desktop" is required for the Shell.Application object (included in
Win2K, WinME, Win98. For Win95/NT4 with a prior install of the optional IE4 "Desktop Update").

set shApp = createobject("shell.application")
set shFolder = shApp.namespace("c:\_temp")
msgbox typename(shFolder)
set shItems = shFolder.Items()
for each shItem in shItems
shItem.invokeverb "&Print"
next

For localized versions of Windows, the text for the "verb" matches what is displayed on the context
menu in Windows Explorer. The & marks the character underlined...

--
Michael Harris
Microsoft.MVP.Scripting
--
mik...@mvps.org
Please do not email questions - post them to the newsgroup instead.
--

"Chris Peel" <chris...@solect.com> wrote in message news:#x5K8b$jAHA.2080@tkmsftngp05...

Tom Hingston

unread,
Feb 6, 2001, 12:04:39 AM2/6/01
to
Hi
 
without testing... what about this (I am sure Michael knows something nicer)
 

Set fso = CreateObject("Scripting.FileSystemObject")

Set Shell = CreateObject("Wscript.Shell")

Set f = fso.GetFolder("C:\MyFolder" )
Set fc = f.Files
   For Each f1 in fc
     if lcase(right(f1.name, 4)) = ".txt" then

        Shell.Run ( f1 )   'open it
         wscript.sleep 2000  'give it time to open
 
        ' use sendkeys to make it print
          Shell.Sendkeys "%F"   'file menu
          Shell.Sendkeys "P"     'print
         wscript.sleep 5000   'give it time to print
          Shell.Sendkeys "%F"   'file menu
          Shell.Sendkeys "x"     'exit       
     end if
   Next 'f1
 
 
HTH
--
Tom
--------------------------------------------------------------------------
http://engines2go.com - Fast access to all the major search engines.
No Ads, Pictures or Banners.
--------------------------------------------------------------------------
http://cheqsoft.com - Home of "Clipboard Express"
The free multiple storage clipboard copy and paste utility.
 
 
"Chris Peel" <chris...@solect.com> wrote in message news:#x5K8b$jAHA.2080@tkmsftngp05...
0 new messages