|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Hi EveryBody!
I am trying to automate the input of a printer form, however when I use Sendkey, it doesn't seem to work. My program automatically prints a word document out using a printer. The defaults of the printer are set to "Print to File." Thus, a little form pops up asking me to enter in the output file name. Is there anyway to automate the entry of an output file name? I tried using SendKey, however it is not working for me. This is what I have: Public Sub PrintDoc(sDoc As String) Dim CurrentPrinter As Printer 'This must be declared. Dim MyDoc As Object 'create a word variable Set MyDoc = CreateObject("Word.Application") With MyDoc For Each CurrentPrinter In Printers If CurrentPrinter.DeviceName = "apple" Then Set Printer = CurrentPrinter Exit For End If Next .Documents.Open sDoc, , True Printer.Print sDoc SendKey "test.prn, {ENTER}" .ActiveDocument.Close 'Close The Document .Quit Set MyDoc = Nothing End With End Sub I think I need to use the .SendKey method, however I don't know what object to use for it. Thanks in advance for your help! ![]() |
|
#2
|
|||
|
|||
|
SendKey "test.prn, {ENTER}" is not correct..
It may be SendKey "test.prn{ENTER}"... |
|
#3
|
|||
|
|||
|
Thanks for your response. I changed it, but it still doesn't work. I don't think it knows what object to send the string to. Does the SendKeys method automatically send the string to the window that is currently in focus?
|
|
#4
|
|||
|
|||
|
Public Sub PrintDoc(sDoc As String)
Dim CurrentPrinter As Printer 'This must be declared. Dim MyDoc As New Word.Application 'Set MyDoc = CreateObject("Word.Application") MyDoc.Documents.Open sDoc, , True MyDoc.PrintOut False, , , , , , , , , , , True, sDoc 'Printer.Print sDoc '.SendKey "test.prn{ENTER}" MyDoc.ActiveDocument.Close 'Close The Document MyDoc.Quit Set MyDoc = Nothing End Sub Private Sub Command1_Click() Call PrintDoc("c:\1.doc") End Sub About printout: Please Visit http://msdn.microsoft.com/library/d...OMMPrintOut.asp |
|
#5
|
|||
|
|||
|
Thanks for your help. I had tried the Printout statement earlier, however it doesn't work the same way as the Printer.print statement. When using the Printout statement, the actual document isn't printed with a printer. I need the document to use the Apple printer because that printer converts my document into a .prn file. Thus, I have to use the Printer.print statement.
My question is, since the default of that Printer is set to "Print to File," how can I automate the input of the file name the printer should print out to? I really appreciate all the help you have given me so far. ![]() |
|
#6
|
|||
|
|||
|
Okay, I was trying out the sendKey code, which is almost the same as the code in the very first post except I got the Syntax for the SendKey right.
Public Sub PrintDoc(sDoc As String) Dim CurrentPrinter As Printer 'This must be declared. Dim MyDoc As Object 'create a word variable 'Set MyDoc = New Word.Application 'create new instance of words Set MyDoc = CreateObject("Word.Application") 'create new instance of words With MyDoc For Each CurrentPrinter In Printers If CurrentPrinter.DeviceName = "apple" Then Set Printer = CurrentPrinter Exit For End If Next .Documents.Open sDoc, , True .Visible = True .Activate Printer.Print sDoc SendKeys "test50.prn{ENTER}" .ActiveDocument.Close 'Close The Document .Quit Set MyDoc = Nothing End With When I run that code the printer tries to print the file to a file. It pops up a box asking for the Print to File name. After I enter in a name manually, it prints "test50" in my test document and saves the document as .prn.doc to my desktop. It also gives me an error because the file is actually a read Only file. Why it is saving the document as a .prn.doc file? Also, if there is no way to access the Print to File form to automate the input of the file name please tell me. That way I can start thinking of different approaches. Thanks. |
|
#7
|
|||
|
|||
|
U can try my program above! It's valid.
|
|
#8
|
|||
|
|||
|
I tried using your code above however I added the For Loop to select the correct printer, right before you open the document. For some reason, the printout statement still prints to the default printer, instead of the printer I selected. Why is that?
|
|
#9
|
|||
|
|||
|
Yes!mela,it's my wrong!
Now correct it! Option Explicit Public Sub PrintDoc(sDoc As String, PrinterName As String) Dim CurrentPrinter As Printer 'This must be declared. Dim MyDoc As New Word.Application 'Set MyDoc = CreateObject("Word.Application") MyDoc.Documents.Open sDoc, , True Application.ActivePrinter = PrinterName MyDoc.ActivePrinter = PrinterName MyDoc.PrintOut False, , , , , , , , , , , True, sDoc 'Printer.Print sDoc '.SendKey "test.prn{ENTER}" MyDoc.ActiveDocument.Close 'Close The Document MyDoc.Quit Set MyDoc = Nothing End Sub Private Sub Command1_Click() Call PrintDoc("c:\devicetable.log", "HP Color LaserJet 8550 PCL 5C") End Sub about ActivePrinter: http://msdn.microsoft.com/library/d...tivePrinter.asp |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Using SendKey for printer forms |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|