Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Laurence Lombard
 
Posts: n/a
Default Printing labels on a dot matrix printer - what does this code do

In my search for a method to print labels on a dot matrix printer from Excel
I found the post http://www.theofficeexperts.com/for...hread.php?t=831 which
gave a fine solution, but there is a bit of code which I do not understand.
(My VBA is self taught via trial and error).

PauseTime = 2 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop

..
The code writes to PRINTLABEL.TXT and then executes a PRINTLABEL.BAT (which
contains the line "copy PRINTLABEL.TXT lpt1") for the number of times one
wants the label printed. I suspect the code above slows down the execution
so that the BAT file does not run faster than the printer can print.

Thanks
Laurence

PS I have looked at David McRitchies suggestions of using Word and
mailmerge, but I prefer this methos as everything is done in Excel (my
preference).


An abbreviated version of the code follows for details sake. It works well
and I thought other that use this forum might also find it useful.

----------------------------------------------------------------------------
--------------
Private Sub PRINTLABEL_Click()
On Error GoTo Err_PRINTLABEL_Click

Dim Message, Title
Dim NUMCOPIES As Integer
Dim PauseTime, Start, Finish, TotalTime
Dim PRINTLINE1 As Variant
Dim PRINTLINE2 As Variant
Dim PRINTLINE3 As Variant
Dim PRINTLINE4 As Variant
Dim PRINTLINE5 As Variant
Dim PRINTLINE6 As Variant
Dim RetVal

Open "c:\PRINTLABEL.TXT" For Output Shared As #1


PRINTLINE1 = [Mr/Mrs] & " " & [ContactFirstName] & " " & [ContactLastName]
PRINTLINE2 = [CompanyName]
PRINTLINE3 = [Address1]
PRINTLINE4 = [Address2]
PRINTLINE5 = [POB]
PRINTLINE6 = [City] & ", " & [StateOrProvince] & " " & [PostalCode]


Print #1, " "
Print #1, (PRINTLINE1)
Print #1, (PRINTLINE2)
Print #1, (PRINTLINE3)
Print #1, (PRINTLINE6)
Print #1, " "
Close #1

NUMCOPY:

PauseTime = 2 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop

Message = "Enter the number of copies"
NUMCOPIES = InputBox(Message, Title, NUMCOPIES + 1)
For counter = 1 To NUMCOPIES

PauseTime = 2 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop


RetVal = Shell("C:\LABPRT.BAT") ' PRINTS LABEL.
Next counter

Exit_PRINTLABEL_Click:
Exit Sub

Err_PRINTLABEL_Click:
MsgBox Err.Description
Resume Exit_PRINTLABEL_Click

End Sub






  #2   Report Post  
Posted to microsoft.public.excel.misc
raypayette
 
Posts: n/a
Default Printing labels on a dot matrix printer - what does this code do


This is old code, probably a QuickBasic legacy!

It seems that the printer needed some delay to process the matter.
If your printer is recognized by Windows® I strongly suggest that you
let Windows handle it. You might need to update the driver by going to
the manufacturer's web page.

I would rework everything from Excel.


--
raypayette


------------------------------------------------------------------------
raypayette's Profile: http://www.excelforum.com/member.php...o&userid=29569
View this thread: http://www.excelforum.com/showthread...hreadid=553051

  #3   Report Post  
Posted to microsoft.public.excel.misc
Laurence Lombard
 
Posts: n/a
Default Printing labels on a dot matrix printer - what does this code do

Thanks for the reply. I reply to the group and directly as I am not sure
whether you would notice replies to "old" posts (at the rate postings are
made to this group they age very quickly). I did notice that if I want to
print many labels only about maximum 7 or 8 get printed, so I assumed this
bit of code was included to handle that.

I worked around it by writing all the labels to the text file and then
copying the text file to lpt1 once only. This works well enough. The only
hitch is that if the printer messes up a label (my printer does that
sometimes - I think it is a mechanical fault) and I switch it off, realign
the labels and switch on, the printing goes on where it left off - with the
alignment most likely out. I would like to have the printer queue cleared if
the printer stops or is switched off. Fortunately the printer is behaving
well and I print in smaller batches of 20.

Laurence

"raypayette" wrote
in message ...

This is old code, probably a QuickBasic legacy!

It seems that the printer needed some delay to process the matter.
If your printer is recognized by Windows® I strongly suggest that you
let Windows handle it. You might need to update the driver by going to
the manufacturer's web page.

I would rework everything from Excel.


--
raypayette


------------------------------------------------------------------------
raypayette's Profile:

http://www.excelforum.com/member.php...o&userid=29569
View this thread: http://www.excelforum.com/showthread...hreadid=553051



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Labels not printing zip codes Michele Excel Discussion (Misc queries) 1 December 6th 05 08:54 PM
Printing labels from excel Linda Excel Discussion (Misc queries) 1 November 12th 05 04:11 PM
my merged address labels are only printing ONE page -- answer? Michelle Excel Discussion (Misc queries) 0 November 7th 05 08:04 AM
Printing Labels Todd Nelson Excel Discussion (Misc queries) 2 August 8th 05 06:49 PM
Printing a Pivot Table from code - Excel 2003 Newbie Excel Discussion (Misc queries) 4 January 5th 05 04:10 PM


All times are GMT +1. The time now is 10:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"