|
-
March 15th, 2001, 02:00 PM
#1
Use VB to send file to printer...
Hi,
this may sound like a simple question, but what is the command to send a file to a printer? I'm trying to use the common dialog box first to choose the network printer to print to, and then use the Printer Object like this...
Printer.print 'FileName
It doesn't seem to want to send the file to the printer, do I have to send the file record by record? Please tell me I can just send the damned file!!!
Thanks,
Sean
-
March 15th, 2001, 02:12 PM
#2
Re: Use VB to send file to printer...
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Dim lngResult As Long
lngResult = ShellExecute(Me.hwnd,"Print",strFile,0&,0&,vbMinimized)
where strFile is the full path to your file
Iouri Boutchkine
[email protected]
-
March 15th, 2001, 02:14 PM
#3
Re: Use VB to send file to printer...
-
March 15th, 2001, 02:30 PM
#4
Re: Use VB to send file to printer...
Wait a second, how do I specify which printer I am printing to with this??? Here is my cmdPrint code:
Dim ReturnVal as string
Dim strFile as string
Dim lngResult as Long
ReturnVal = Dir(LABELDIRECTORY & strOrder & ".d00")
If ReturnVal = strOrder & ".d00" then
ReturnVal = MsgBox("is the printer set up correctly?", vbYesNo, "LabelMaker")
If ReturnVal = vbNo then
Exit Sub
End If
cdlLabel.ShowPrinter
strFile = LABELDIRECTORY & strOrder & ".d00"
lngResult = ShellExecute(me.hwnd, "print", strFile, 0&, 0&, vbMinimized)
MsgBox "Labels have begun to print..."
End If
Nothing happens....I use the ShowPrinter method of the coommon dialog box to specify printer, and then used ShellExecute.
Ideas?
-
March 15th, 2001, 02:44 PM
#5
Re: Use VB to send file to printer...
It will print to the default printer.
If you want to change the printer
Here the code
Private Function SelectPrinter(ByVal printer_name As String) As Boolean
Dim i As Integer
SelectPrinter = True
For i = 0 To Printers.Count - 1
If Printers(i).DeviceName = printer_name Then
Set Printer = Printers(i)
SelectPrinter = False
Exit For
End If
Next i
End Function
Private Sub Form_Load()
Dim i As Integer
cboPrinter.Clear
For i = 0 To Printers.Count - 1
cboPrinter.AddItem Printers(i).DeviceName
Next i
End Sub
'choose in combo printer_name
Iouri Boutchkine
[email protected]
-
March 15th, 2001, 09:45 PM
#6
Re: Use VB to send file to printer...
Depends upon the formfat of your file. The ShellExecute will work if your file is a registered type. Here is a code sample that should work (I haven't tested it though). It will print to the printer you select with a CommonDialog Box.
'Printing a file involves opening the file, reading into a byte array,
'converting from Unicode format to ASCII and sending the converted string to the printer.
dim FileHandle as Integer
Dim FileAsByte() as Byte
Dim FileAsStr as string
FileHandle = FreeFile
Open "Filename.ext" for binary as FileHandle
ReDim FileAsByte(LOF(FileHandle))
get PPTFileHandle, , FileAsByte
FileAsStr = StrConv(FileAsByte(), vbUnicode)
Close PPTFileHandle
Printer.print FileAsStr
FileAsStr = ""
Redim FileAsByte(1)
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|