Results 1 to 13 of 13
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print Labels (VBA/Word/97+)

    Hello

    I had a request to create a macro in MS Word that allowed a user to specify which label to print (or not print) when just a single or a couple of labels were required. This happens when a sheet of labels hasn't been completely used and there may be a few left.

    So far I have created a Userform that has options in a frame and checkboxes that the user clicks to specify the type of label sheet they are using (eg 3 x 8) and the postion of the label to be printed (via the checkbox). My project is not complete as I am not sure about how to step through the cells of the page that has the labels data.

    The attached is a screen capture of the form and I'll happily post the code for anyone that is interested in helping with the project.

    I imagine the finished project will be either a menu or toolbar button option but could also be an add-in for word with an attendant toolbar button.

    Suggestions welcome.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Labels (VBA/Word/97+)

    Will the source data in the Word document always be in the same layout as the label setup chosen in the left hand frame? Or do you need to convert the data to the chosen label setup? (If not, what happens if the user selects a label setup that does not conform to the layout of the document?)

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Print Labels (VBA/Word/97+)

    I'm with Hans - you should be obtaining the page layout from the document layout rather than asking the user to describe the page.

    You should also verify that this is a mail merge document before showing the form at all.

    Once that is done, I would ask for the number of rows before the labels start and insert that many empty rows at the top of the table. I wouldn't bother with the unused columns in the topmost row on the grounds that the effort is not worth it. The money they save in stationery costs is going to be overpowered by the time it takes to code for it and the time it takes them to provide that information correctly.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Labels (VBA/Word/97+)

    I should give some more detail.
    * This process is not intended for mail-merge.
    * Currently there are a number of templates that match the label sheets with the required labels already on them.
    * The labels are meant for product (cans/cartons) and are printed as required.
    * Sometimes, not a whole sheet is used, and rather than waste it, currently the template is opened and the 'not to be printed' labels are changed to white font.
    * The user will choose the label type from the left frame and then select the labels to print from the right frame checkboxes.

    Currently, only the label types shown are in use. (ie 2 across by 2 down, 2 across by 4 down,... 3 across by 8 down) but the form can be modified to suit the actual template (read label sheet type).

    Does that make it easier to understand?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Labels (VBA/Word/97+)

    You could use something like this - adapt as needed. It assumes:

    - You have named the check boxes in the right hand frame chkR1C1, chkR1C2 etc. This makes it possible to loop through the check boxes by row and column number.
    - You have defined and assigned variables lngNumberOfRows and lngNumberOfColumns according to the label type selected in the left hand frame.

    Private Sub cmdOK_Click()
    Dim i As Long
    Dim j As Long
    Dim tbl As Table
    Set tbl = ActiveDocument.Tables(1)
    For i = 1 To lngNumberOfRows
    For j = 1 To lngNumberOfColumns
    If Me.Controls("chkR" & i & "C" & j) = False Then
    tbl.Cell(i, j).Range.Delete
    End If
    Next j
    Next i
    Set tbl = Nothing
    Unload Me
    End Sub

    You can replace ...Range.Delete by something else that will suppress printing, such as making the text hidden, or white, if you prefer.

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Labels (VBA/Word/97+)

    Thanks Hans,

    That code was exactly what was needed - I did modify it to print the request and just to make sure that the labels template was closed without saving changes.

    Do you think other Loungers would benefit from the whole code being posted?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Labels (VBA/Word/97+)

    Yes, if you don't mind sharing it, it would be nice if you posted the result. If the code is longish, please post it in an attachment; if you want to post the template, either rename it to .doc, or zip it - you can't attach a .dot file to a post. Thanks!

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Labels (VBA/Word/97+)

    Attachment contains a macro suitable for selecting which labels you want to print from a sheet when the Avery (or whichever brand) label sheet has been partly used.

    If you think the code is not efficiently written then by all means please post a reply. I am happy to see others suggestions.

    To use this code I would think that you would open the MS Word attachment and copy the userform (frmLabelSelect) and the module (labelPrint) to your Normal.dot template. Then create a simple toolbar button to run the macro.

    If you have any suggestions on improvements please post.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Labels (VBA/Word/97+)

    Most of it is fine, but this bit

    MsgBox "Click OK to close file without saving changes or Cancel to return to document.", vbOKCancel
    If vbOK = 1 Then
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    Else: End
    End If

    won't work as intended. You actually don't do anything with the button clicked by the user in the message box. Try this instead:

    If MsgBox("Click OK to close file without saving changes or Cancel to return to document.", vbOKCancel + vbQuestion) = vbOK Then
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    End If

    Depending on the average utilization of the label sheets, you may want to turn on all visible check boxes when the form is opened.

  10. #10
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Print Labels (VBA/Word/97+)

    Leigh

    I thought I would have a play to make reduce some of the code and add another button to help tick the remaining checkboxes. It is not going to run any faster but should be quicker to maintain this way.

    I didn't make Hans suggested change so if you use this version you will need to add that in. I would also default the checkboxes as filled although I think my addition of the add remainder simplifies the task of checking all the boxes. The new button is meant to be used when one of the checkboxes is ticked to tick the subsequent ones. Your mileage will vary if multiple checkboxes are selected when the button is pressed <img src=/S/sad.gif border=0 alt=sad width=15 height=15>
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  11. #11
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Labels (VBA/Word/97+)

    Andrew, I must lead a sheltered life - but I must admit that I like what both you and Hans have offered!! Just brilliant and I am very appreciative of the insight I have gained from your replies.

    Attachment is the revised version for any Loungers that are following this thread. It incorporates the features mentioned by both Hans and Andrew and a small cleanup to the userform and added a toolbar button to a new toolbar that is attached to the document. As before, I would suggest that the userform, module and the toolbar button be moved to your Normal.dot so that it can be available whenever you need to print partial label sheets.

    It is not intended for use with the mailmerge command - although maybe it could be modified.

  12. #12
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Print Labels (VBA/Word/97+)

    Leigh

    I would set this to work without adding it to Normal.dot. I think it is specialised enough to be of little use unless working in a very restricted set of documents. Because of the specialised nature I would tend to not clutter the Normal template with it.

    You can do this by saving it as a template and then going into Tools > Templates and Addins and adding it to the addin list. I would then leave it 'ticked off' in everyday use but when you want it you can go to this dialog and turn it on to gain access to it. If you leave it 'ticked on' then you have it anytime you like but you can free up a little memory by leaving it off when it isn't needed.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  13. #13
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Brisbane, Australia
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Labels (VBA/Word/97+)

    Thanks Andrew, I take your advice and agree that it would be best as an occasional add-in due to its expected limited use.

    Thanks for your input...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •