Creating labels

B

Brian

I'm taking my first shot at creating a macro in Word using VBA that will create labels based on user input. Basically what I'm trying to do is have a dialog box open that allows the users to input starting and ending ranges for the labels, then have the macro go and build the label / document.

I've been following some tutorials and the net and so far have successfully (I think) created a dialog box that allows for the starting and ending ranges to be input. However, I can't seem to find any sample code that shows how to create the label. Once I get that, I should (I think) be able to supply my captured variables for the values.

Any ideas ?


Thanks in advance,
Brian
 
J

Jonathan West

Hi brian

Are these labels where you have multiple labels to a sheet?

If so, the normal approach is to define a table with the name number of rows
& columns as the label sheet has, and make sure the row heights and column
widths are set so that the cell borders fall in the same places as the label
edges.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

I'm taking my first shot at creating a macro in Word using VBA that will
create labels based on user input. Basically what I'm trying to do is have
a dialog box open that allows the users to input starting and ending ranges
for the labels, then have the macro go and build the label / document.

I've been following some tutorials and the net and so far have successfully
(I think) created a dialog box that allows for the starting and ending
ranges to be input. However, I can't seem to find any sample code that
shows how to create the label. Once I get that, I should (I think) be able
to supply my captured variables for the values.

Any ideas ?


Thanks in advance,
Brian
 
B

Brian

Yes, there will definitely be multiple labels on a single page (about 60 or
so) and they would run sequentially. So the dialog box basically asks the
user what the starting and ending range is and any characters that should
precede that range, such as ABC.

If the user inputs "starting number" 1 and "ending number" 100 with a prefix
of "ABC", then the first label would be ABC-001, second label ABC-002, third
label ABC-003, etc.

So then I would need to create a table rather than labels?
 
J

Jonathan West

Brian said:
Yes, there will definitely be multiple labels on a single page (about 60
or
so) and they would run sequentially. So the dialog box basically asks the
user what the starting and ending range is and any characters that should
precede that range, such as ABC.

If the user inputs "starting number" 1 and "ending number" 100 with a
prefix
of "ABC", then the first label would be ABC-001, second label ABC-002,
third
label ABC-003, etc.

So then I would need to create a table rather than labels?

Create your table with the appropriate number of rows & columns. Make sure
that if you put some test in the cells, it prints neatly into the middle of
each label.

Once you have created the table, you can do something like this to fill the
cells.

Dim iRow as Long
Dim iCol as Long
Dim iSequence as Long

For iRow = 1 to 10
For iCol = 1 to 6
iSequence = iSequence + 1
ActiveDocument.Tables(1).Cell(iRow, iCol).Range.Text = _
"ABC-" & Format(iSequence, "000")
Next iCol
Next iRow


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
G

Graham Mayor

As an alternative approach to that suggested by Jonathan - see
http://www.gmayor.com/Numbered_labels.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

I'm taking my first shot at creating a macro in Word using VBA that will
create labels based on user input. Basically what I'm trying to do is have
a dialog box open that allows the users to input starting and ending ranges
for the labels, then have the macro go and build the label / document.

I've been following some tutorials and the net and so far have successfully
(I think) created a dialog box that allows for the starting and ending
ranges to be input. However, I can't seem to find any sample code that
shows how to create the label. Once I get that, I should (I think) be able
to supply my captured variables for the values.

Any ideas ?


Thanks in advance,
Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top