SunQuest
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old September 8th, 2003, 12:39 PM
mela mela is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 8 mela User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Using SendKey for printer forms

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!

Reply With Quote
  #2  
Old September 9th, 2003, 01:30 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
SendKey "test.prn, {ENTER}" is not correct..
It may be SendKey "test.prn{ENTER}"...

Reply With Quote
  #3  
Old September 9th, 2003, 06:35 PM
mela mela is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 8 mela User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #4  
Old September 9th, 2003, 11:33 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
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

Reply With Quote
  #5  
Old September 10th, 2003, 11:56 AM
mela mela is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 8 mela User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old September 10th, 2003, 01:07 PM
mela mela is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 8 mela User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #7  
Old September 10th, 2003, 08:00 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
U can try my program above! It's valid.

Reply With Quote
  #8  
Old September 11th, 2003, 12:53 PM
mela mela is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 8 mela User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #9  
Old September 11th, 2003, 10:40 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Using SendKey for printer forms


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway