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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a way to print from a vbs? 4

Status
Not open for further replies.

barny2006

MIS
Mar 30, 2006
521
US
hi,
is there a way to print a list or something like a message onto a printer from a vbs program? i understand that in .hta, you can use window.print() to print something. i'm not sure about vbs.
any guidance on this?
thanks.
 
Not certain about the dialog box, but you can print items with objitem.InvokeVerbEx("Print"). This works pretty well for everything except PDF's, since the Acrobat executable (different for reader or Pro) doesn't close down after the print job is completed.
 
thanks, babs,
how would i set this up? let's i want to print the variable msg, how would i use that objitem to print msg?
 
If you wanted to print a message you could temporarily write your message to text file and then print it with something like this.

You could do it like this.

Code:
Option Explicit
'On Error Resume Next

Dim objShell, objFolder, objFile

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace("c:\temp")
Set objFile = objFolder.ParseName("test.txt")
objFile.InvokeVerb("Print")

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
thanks dm,
this is just printing a file. i think it can be done with dos shell command too. i'm after something that will print a list that's in a variable. instead of using msgbox, just to print the list.
 
I found this by Tom Lavedas. Worked when I tried it. No dialog box appeared or anything. Still need to write it out to a file first though.

Code:
Option Explicit
'On Error Resume Next

Dim objFSO

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "c:\temp\test.txt", "\\server\printer"

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
awesome, we both learned something new which i've thought about doing before.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
in the older days you used to redirect stdout to LPT1 etc

c:\test.txt > LPT1

i think

 
yeah,
that's the good ole days of dos. i occasionally use dos shell commands. i think it may work in this case too. is it possible?
 
thanks hugh
i'll give it a try, see what happens. right now i'm using a file and "invokeverb" deal, as suggested by most.
 
i tried the Echo var>prn.
i think that it tried to send something to the printer. but tne network won't allow it, because the document doesn't have a name.

 
Just one more option. since there are so many ways to do this!

Code:
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
Dim WshShell
set WshShell = CreateObject("wscript.Shell")

strDefaultPrinter = "\\[PrintServer]\[PrintShare]"
strPrintFile = "[File name with full path]"
'Example strPrinFile = "C:\Myfile.txt"

WshShell.Run ("[Application] /P " & strPrintFile)
'Example WshShell.Run ("%SystemRoot%\system32\notepad.exe /P " & PrintFile)

Thanks

John Fuhrman
Titan Global Services
 
sparks,
thanks.
this is jsut a file print. file > print.
the ideal solution is variable to print. var > print.
i have already used invokeverb to print a temp file. i'm looking for a way to print without a file. could this code work witout a file? if it does, then that's what i'm looking for.
thanks so much.
 
Actually what I was thinking was to use SendKeys to insert the text into notepad then tell notepad to print and exit without saving. I just have been to busy to keep going on my original idea. [morning]

Thanks

John Fuhrman
Titan Global Services
 
spark,
that's cool. i'm familiar with sendkey deal. actually i've done several apps with sendkey and notepad. thanks. i think this will work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top