help with macros

G

Guest

Hi All.

I have to create a mail merge button which when clicked will merge specific
selected feilds from a word document and create a label tag.


I want to know if this can be automated and done. Ideally the user should be
prompted for what to enter and based on his input the values should be
displayed as a label.

Thanks for your help in advance.
 
G

Graham Mayor

This doesn't sound much like a merge to me? You appear to want to extract
information from a document and create a label from that information? That
being the case, what is the information and how will the macro recognize it
from the document?

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

Hi Graham,

Yes you are right. I need to extract specific field values from a word
document and create a label tag out of it.

I have an inspection report which has project data like Project desc,
project no, Component desc, Dwg no input. I have to extract this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which extracts data to
print will be of immense help.

Thanks in advance.
 
D

Doug Robbins - Word MVP

You would have to advise how the data is arranged in the reports, is the
data always arranged in that way, etc. before anyone could suggest a macro
to you.

You might want to think however about designing the reports so that the data
extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Guest

Hello Doug,

Thanks for your reply. I have gone through the Auto Form document and would
require some help.

Bear with me I am not very good at macros and dont totally understand the
concept of bookmark. If I am not wrong Bookmark gives you the location of
each feild typed in.


With my limited knowlege i have created a form which has input text feilds
to store information of the user. I am attempting to extract these values. I
have named each text box form feild with a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG [ ]

TOT QTY [ ]

each square bracket representing a text form feild with bookmarks for each
feild. Now how to extract the values for these once the user inputs them. The
order of these entries do not change. Based on the entries i have to create
a product tag for merging labels. Is this possible. How do i proceed from
here.
 
G

Graham Mayor

http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how to extract
data from a form, however, if the object of the exercise is for a user to
input data into the form and produce a label, then the following macro will
do that (with certain provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label Columns"
GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)", Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _
Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are using.
To get the correct label name record a macro of printing anything to that
label format and extract the name from the resulting macro.
That label must be large enough to fit the text as shown in the message
prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you have named
the field bookmarks differently to give more meaningful descriptions, you
will have to change the bookmark names Text1-7


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Hello Doug,

Thanks for your reply. I have gone through the Auto Form document and
would require some help.

Bear with me I am not very good at macros and dont totally understand
the concept of bookmark. If I am not wrong Bookmark gives you the
location of each feild typed in.


With my limited knowlege i have created a form which has input text
feilds to store information of the user. I am attempting to extract
these values. I have named each text box form feild with a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG [ ]

TOT QTY [ ]

each square bracket representing a text form feild with bookmarks for
each feild. Now how to extract the values for these once the user
inputs them. The order of these entries do not change. Based on the
entries i have to create a product tag for merging labels. Is this
possible. How do i proceed from here.


Doug Robbins - Word MVP said:
You would have to advise how the data is arranged in the reports, is
the data always arranged in that way, etc. before anyone could
suggest a macro to you.

You might want to think however about designing the reports so that
the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Guest

Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do this.

1) the printer while printing labels is by Stack byPass as defualt so the
printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)", Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I mention this
here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the normal print
command can i do this with a macro.

4) when i protect the form and enter values i cannot run the macro. I
unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the form
feilds, is this correct.

Please bear with me if these questions are real basic but I am beginning to
understand the power of macros and its automation capabilities and attempting
to grasp the concept.


thanks





Graham Mayor said:
http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how to extract
data from a form, however, if the object of the exercise is for a user to
input data into the form and produce a label, then the following macro will
do that (with certain provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label Columns"
GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)", Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _
Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are using.
To get the correct label name record a macro of printing anything to that
label format and extract the name from the resulting macro.
That label must be large enough to fit the text as shown in the message
prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you have named
the field bookmarks differently to give more meaningful descriptions, you
will have to change the bookmark names Text1-7


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Hello Doug,

Thanks for your reply. I have gone through the Auto Form document and
would require some help.

Bear with me I am not very good at macros and dont totally understand
the concept of bookmark. If I am not wrong Bookmark gives you the
location of each feild typed in.


With my limited knowlege i have created a form which has input text
feilds to store information of the user. I am attempting to extract
these values. I have named each text box form feild with a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG [ ]

TOT QTY [ ]

each square bracket representing a text form feild with bookmarks for
each feild. Now how to extract the values for these once the user
inputs them. The order of these entries do not change. Based on the
entries i have to create a product tag for merging labels. Is this
possible. How do i proceed from here.


Doug Robbins - Word MVP said:
You would have to advise how the data is arranged in the reports, is
the data always arranged in that way, etc. before anyone could
suggest a macro to you.

You might want to think however about designing the reports so that
the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values from a
word document and create a label tag out of it.

I have an inspection report which has project data like Project
desc, project no, Component desc, Dwg no input. I have to extract
this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which extracts
data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to want to
extract information from a document and create a label from that
information? That
being the case, what is the information and how will the macro
recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked will merge
specific selected feilds from a word document and create a label
tag.


I want to know if this can be automated and done. Ideally the user
should be prompted for what to enter and based on his input the
values should be displayed as a label.

Thanks for your help in advance.
 
G

Graham Mayor

To overcome the variables try the following:

1. The revised version below creates a new label document, so you can print
as many labels as you like on whatever printer you have available.
2. The default label size is 5263, but you can insert another number if you
change this.
3. See 1
4. Run the macro from a toolbar button or better still on exit from the last
form field. The macro will then unlock and lock the form.
5. It doesn't matter what you call the form field bookmarks as long as the
names are echoed in the macro Text1 to 7 are what I used.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel, Address:=sLayout
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub





Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do this.

1) the printer while printing labels is by Stack byPass as defualt so
the printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)", Address:=sLayout,
_
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I mention
this here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the normal
print command can i do this with a macro.

4) when i protect the form and enter values i cannot run the macro. I
unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the form
feilds, is this correct.

Please bear with me if these questions are real basic but I am
beginning to understand the power of macros and its automation
capabilities and attempting to grasp the concept.


thanks





Graham Mayor said:
http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how to
extract data from a form, however, if the object of the exercise is
for a user to input data into the form and produce a label, then the
following macro will do that (with certain provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label Columns"
GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _ ExtractAddress:=False,
SingleLabel:=True, _ Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are using.
To get the correct label name record a macro of printing anything to
that label format and extract the name from the resulting macro.
That label must be large enough to fit the text as shown in the
message prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you have
named the field bookmarks differently to give more meaningful
descriptions, you will have to change the bookmark names Text1-7


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Hello Doug,

Thanks for your reply. I have gone through the Auto Form document
and would require some help.

Bear with me I am not very good at macros and dont totally
understand the concept of bookmark. If I am not wrong Bookmark
gives you the location of each feild typed in.


With my limited knowlege i have created a form which has input text
feilds to store information of the user. I am attempting to extract
these values. I have named each text box form feild with a book
mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG [ ]

TOT QTY [ ]

each square bracket representing a text form feild with bookmarks
for each feild. Now how to extract the values for these once the
user inputs them. The order of these entries do not change. Based
on the entries i have to create a product tag for merging labels.
Is this possible. How do i proceed from here.


:

You would have to advise how the data is arranged in the reports,
is the data always arranged in that way, etc. before anyone could
suggest a macro to you.

You might want to think however about designing the reports so that
the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values from a
word document and create a label tag out of it.

I have an inspection report which has project data like Project
desc, project no, Component desc, Dwg no input. I have to extract
this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which extracts
data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to want to
extract information from a document and create a label from that
information? That
being the case, what is the information and how will the macro
recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked will
merge specific selected feilds from a word document and create
a label tag.


I want to know if this can be automated and done. Ideally the
user should be prompted for what to enter and based on his
input the values should be displayed as a label.

Thanks for your help in advance.
 
G

Guest

Hello Graham,

This macro code works beautifully. The labels are getting printed the way it
should be. I am still trying to overcome a printer word problem.

In word during mail merge when you select avery shipping label option the
Laser and ink jet tray shows systemBypass to allow manual feed.

When i run this macro the printer detects labels are being printed and gives
an error.I manually select auto paper size A4 and the data is printed. I
tried putting the label in the tray but it did not work either. It flashes
with Staybypass option. Is there any way a default paper tray can be
selected. We use printers in remote location and are looking at getting a
dedicated printer for this purpose.

Can the user select the tray from which he wants to print might be that way
we can work around this problem.

Graham Mayor said:
To overcome the variables try the following:

1. The revised version below creates a new label document, so you can print
as many labels as you like on whatever printer you have available.
2. The default label size is 5263, but you can insert another number if you
change this.
3. See 1
4. Run the macro from a toolbar button or better still on exit from the last
form field. The macro will then unlock and lock the form.
5. It doesn't matter what you call the form field bookmarks as long as the
names are echoed in the macro Text1 to 7 are what I used.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel, Address:=sLayout
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub





Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do this.

1) the printer while printing labels is by Stack byPass as defualt so
the printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)", Address:=sLayout,
_
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I mention
this here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the normal
print command can i do this with a macro.

4) when i protect the form and enter values i cannot run the macro. I
unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the form
feilds, is this correct.

Please bear with me if these questions are real basic but I am
beginning to understand the power of macros and its automation
capabilities and attempting to grasp the concept.


thanks





Graham Mayor said:
http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how to
extract data from a form, however, if the object of the exercise is
for a user to input data into the form and produce a label, then the
following macro will do that (with certain provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label Columns"
GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _ ExtractAddress:=False,
SingleLabel:=True, _ Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are using.
To get the correct label name record a macro of printing anything to
that label format and extract the name from the resulting macro.
That label must be large enough to fit the text as shown in the
message prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you have
named the field bookmarks differently to give more meaningful
descriptions, you will have to change the bookmark names Text1-7


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

My web site www.gmayor.com

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

vandy wrote:
Hello Doug,

Thanks for your reply. I have gone through the Auto Form document
and would require some help.

Bear with me I am not very good at macros and dont totally
understand the concept of bookmark. If I am not wrong Bookmark
gives you the location of each feild typed in.


With my limited knowlege i have created a form which has input text
feilds to store information of the user. I am attempting to extract
these values. I have named each text box form feild with a book
mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG [ ]

TOT QTY [ ]

each square bracket representing a text form feild with bookmarks
for each feild. Now how to extract the values for these once the
user inputs them. The order of these entries do not change. Based
on the entries i have to create a product tag for merging labels.
Is this possible. How do i proceed from here.


:

You would have to advise how the data is arranged in the reports,
is the data always arranged in that way, etc. before anyone could
suggest a macro to you.

You might want to think however about designing the reports so that
the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values from a
word document and create a label tag out of it.

I have an inspection report which has project data like Project
desc, project no, Component desc, Dwg no input. I have to extract
this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which extracts
data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to want to
extract information from a document and create a label from that
information? That
being the case, what is the information and how will the macro
recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked will
merge specific selected feilds from a word document and create
a label tag.


I want to know if this can be automated and done. Ideally the
user should be prompted for what to enter and based on his
input the values should be displayed as a label.

Thanks for your help in advance.
 
G

Graham Mayor

You can select the label tray from the print dialog - you should also be
able to edit the tray from the envelope/label dialog - options.
You can do any of this by macro if you know the parameters - see the
examples for selectring alternative printers and/or trays at
http://www.gmayor.com/fax_from_word.htm

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

My web site www.gmayor.com

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

Hello Graham,

This macro code works beautifully. The labels are getting printed the
way it should be. I am still trying to overcome a printer word
problem.

In word during mail merge when you select avery shipping label option
the Laser and ink jet tray shows systemBypass to allow manual feed.

When i run this macro the printer detects labels are being printed
and gives an error.I manually select auto paper size A4 and the data
is printed. I tried putting the label in the tray but it did not work
either. It flashes with Staybypass option. Is there any way a default
paper tray can be selected. We use printers in remote location and
are looking at getting a dedicated printer for this purpose.

Can the user select the tray from which he wants to print might be
that way we can work around this problem.

Graham Mayor said:
To overcome the variables try the following:

1. The revised version below creates a new label document, so you
can print as many labels as you like on whatever printer you have
available.
2. The default label size is 5263, but you can insert another number
if you change this.
3. See 1
4. Run the macro from a toolbar button or better still on exit from
the last form field. The macro will then unlock and lock the form.
5. It doesn't matter what you call the form field bookmarks as long
as the names are echoed in the macro Text1 to 7 are what I used.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub





Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do
this.

1) the printer while printing labels is by Stack byPass as defualt
so the printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I mention
this here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the
normal print command can i do this with a macro.

4) when i protect the form and enter values i cannot run the macro.
I unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the
form feilds, is this correct.

Please bear with me if these questions are real basic but I am
beginning to understand the power of macros and its automation
capabilities and attempting to grasp the concept.


thanks





:

http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how
to extract data from a form, however, if the object of the
exercise is for a user to input data into the form and produce a
label, then the following macro will do that (with certain
provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label Columns"
GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _ ExtractAddress:=False,
SingleLabel:=True, _ Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are using.
To get the correct label name record a macro of printing anything
to that label format and extract the name from the resulting macro.
That label must be large enough to fit the text as shown in the
message prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you have
named the field bookmarks differently to give more meaningful
descriptions, you will have to change the bookmark names Text1-7


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

My web site www.gmayor.com

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

vandy wrote:
Hello Doug,

Thanks for your reply. I have gone through the Auto Form document
and would require some help.

Bear with me I am not very good at macros and dont totally
understand the concept of bookmark. If I am not wrong Bookmark
gives you the location of each feild typed in.


With my limited knowlege i have created a form which has input
text feilds to store information of the user. I am attempting to
extract these values. I have named each text box form feild with
a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG [
]

TOT QTY [ ]

each square bracket representing a text form feild with bookmarks
for each feild. Now how to extract the values for these once the
user inputs them. The order of these entries do not change. Based
on the entries i have to create a product tag for merging labels.
Is this possible. How do i proceed from here.


:

You would have to advise how the data is arranged in the reports,
is the data always arranged in that way, etc. before anyone could
suggest a macro to you.

You might want to think however about designing the reports so
that the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself
of my services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values from
a word document and create a label tag out of it.

I have an inspection report which has project data like Project
desc, project no, Component desc, Dwg no input. I have to
extract this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which
extracts data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to want
to extract information from a document and create a label from
that information? That
being the case, what is the information and how will the macro
recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked will
merge specific selected feilds from a word document and create
a label tag.


I want to know if this can be automated and done. Ideally the
user should be prompted for what to enter and based on his
input the values should be displayed as a label.

Thanks for your help in advance.
 
G

Guest

Hello Graham,

Thanks for the document giving me an option for selecting the tray. I am new
woking with macros and have attempted to add the code with the exisiting
macro you gave me.
I am running into run time errors.

I am getting the users input to print the labels and assuming that this
macro will print from drawer 1 thus choosing the tray and if not than it
print out from drawer 2.



Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

Dim sCurrentPrinter As String
Dim sTray As String
Dim sQuery As String

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel, Address:=sLayout
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If



sQuery = MsgBox("Print Labels?", vbYesNo, "Labels")
If sQuery = vbYes Then 'Answer is print labels

ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the required
printer

Options.DefaultTray = "Drawer 1" 'set labels to Tray 1
End If

If sQuery = vbNo Then 'Answer is regular document
ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the required
printer
Options.DefaultTray = "Drawer 2" 'Set labels to Tray 2
End If

With Dialogs(wdToolsEnvelopesAndLabels)
sCurrentPrinter = ActivePrinter 'Save the current printer
sTray = Options.DefaultTray 'Save the current tray
'ask the user whether labels are required
..DoNotSetAsSysDefault = True
.Execute
Dialogs(wdDialogToolsEnvelopesAndLabels).Show 'Pop up the wizard dialog
ActivePrinter = sCurrentPrinter 'Put the printer back as it was at the start
Options.DefaultTray = sTray 'Put the tray back as it was at the start
DoNotSetAsSysDefault = True
.Execute
End With
End Sub

window shuts down and word autosaves my document. Where am i going wrong.

Thanks for the help.


Graham Mayor said:
You can select the label tray from the print dialog - you should also be
able to edit the tray from the envelope/label dialog - options.
You can do any of this by macro if you know the parameters - see the
examples for selectring alternative printers and/or trays at
http://www.gmayor.com/fax_from_word.htm

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

My web site www.gmayor.com

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

Hello Graham,

This macro code works beautifully. The labels are getting printed the
way it should be. I am still trying to overcome a printer word
problem.

In word during mail merge when you select avery shipping label option
the Laser and ink jet tray shows systemBypass to allow manual feed.

When i run this macro the printer detects labels are being printed
and gives an error.I manually select auto paper size A4 and the data
is printed. I tried putting the label in the tray but it did not work
either. It flashes with Staybypass option. Is there any way a default
paper tray can be selected. We use printers in remote location and
are looking at getting a dedicated printer for this purpose.

Can the user select the tray from which he wants to print might be
that way we can work around this problem.

Graham Mayor said:
To overcome the variables try the following:

1. The revised version below creates a new label document, so you
can print as many labels as you like on whatever printer you have
available.
2. The default label size is 5263, but you can insert another number
if you change this.
3. See 1
4. Run the macro from a toolbar button or better still on exit from
the last form field. The macro will then unlock and lock the form.
5. It doesn't matter what you call the form field bookmarks as long
as the names are echoed in the macro Text1 to 7 are what I used.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub






vandy wrote:
Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do
this.

1) the printer while printing labels is by Stack byPass as defualt
so the printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I mention
this here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the
normal print command can i do this with a macro.

4) when i protect the form and enter values i cannot run the macro.
I unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the
form feilds, is this correct.

Please bear with me if these questions are real basic but I am
beginning to understand the power of macros and its automation
capabilities and attempting to grasp the concept.


thanks





:

http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how
to extract data from a form, however, if the object of the
exercise is for a user to input data into the form and produce a
label, then the following macro will do that (with certain
provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label Columns"
GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _ ExtractAddress:=False,
SingleLabel:=True, _ Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are using.
To get the correct label name record a macro of printing anything
to that label format and extract the name from the resulting macro.
That label must be large enough to fit the text as shown in the
message prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you have
named the field bookmarks differently to give more meaningful
descriptions, you will have to change the bookmark names Text1-7


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

My web site www.gmayor.com

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

vandy wrote:
Hello Doug,

Thanks for your reply. I have gone through the Auto Form document
and would require some help.

Bear with me I am not very good at macros and dont totally
understand the concept of bookmark. If I am not wrong Bookmark
gives you the location of each feild typed in.


With my limited knowlege i have created a form which has input
text feilds to store information of the user. I am attempting to
extract these values. I have named each text box form feild with
a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG [
]

TOT QTY [ ]

each square bracket representing a text form feild with bookmarks
for each feild. Now how to extract the values for these once the
user inputs them. The order of these entries do not change. Based
on the entries i have to create a product tag for merging labels.
Is this possible. How do i proceed from here.


:

You would have to advise how the data is arranged in the reports,
is the data always arranged in that way, etc. before anyone could
suggest a macro to you.

You might want to think however about designing the reports so
that the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself
of my services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values from
a word document and create a label tag out of it.

I have an inspection report which has project data like Project
desc, project no, Component desc, Dwg no input. I have to
extract this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which
extracts data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to want
to extract information from a document and create a label from
that information? That
being the case, what is the information and how will the macro
recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked will
merge specific selected feilds from a word document and create
a label tag.


I want to know if this can be automated and done. Ideally the
user should be prompted for what to enter and based on his
 
G

Graham Mayor

You have to walk before you can run ;)

First clean up the mess from the crash -
http://www.gmayor.com/what_to_do_when_word_crashes.htm

You are going wrong by using the wrong bit of macro code. The one you have
used intercepts the envelope/label dialog. The posted macro has already used
that and the label has been created. All you need is to set the printer and
tray and pop up the print dialog.

Your modifications seem to suggest that the same printer is used throughout.
That being the case there is no need to change it. You can change the Tray
(are you sure that "Drawer 1" is the correct command? Record the action in a
temporary macro if you are not sure) and change it back. The additions below
pop up the print dialog so you can print as many labels as required or
change the tray further if required.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim sTray As String
Dim sName As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'get the filename of the form document
sName = ActiveDocument.FullName
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel, Address:=sLayout

'Print the labels
sTray = Options.DefaultTray
Options.DefaultTray = "Drawer 1"
Dialogs(wdDialogFilePrint).Show
Options.DefaultTray = sTray
'Switch back to the form document
Windows(sName).Activate

'Reprotect the form document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Hello Graham,

Thanks for the document giving me an option for selecting the tray. I
am new woking with macros and have attempted to add the code with the
exisiting macro you gave me.
I am running into run time errors.

I am getting the users input to print the labels and assuming that
this macro will print from drawer 1 thus choosing the tray and if not
than it print out from drawer 2.



Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

Dim sCurrentPrinter As String
Dim sTray As String
Dim sQuery As String

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If



sQuery = MsgBox("Print Labels?", vbYesNo, "Labels")
If sQuery = vbYes Then 'Answer is print labels

ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the
required printer

Options.DefaultTray = "Drawer 1" 'set labels to Tray 1
End If

If sQuery = vbNo Then 'Answer is regular document
ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the
required printer
Options.DefaultTray = "Drawer 2" 'Set labels to Tray 2
End If

With Dialogs(wdToolsEnvelopesAndLabels)
sCurrentPrinter = ActivePrinter 'Save the current printer
sTray = Options.DefaultTray 'Save the current tray
'ask the user whether labels are required
.DoNotSetAsSysDefault = True
.Execute
Dialogs(wdDialogToolsEnvelopesAndLabels).Show 'Pop up the wizard
dialog ActivePrinter = sCurrentPrinter 'Put the printer back as it
was at the start Options.DefaultTray = sTray 'Put the tray back as it
was at the start DoNotSetAsSysDefault = True
.Execute
End With
End Sub

window shuts down and word autosaves my document. Where am i going
wrong.

Thanks for the help.


Graham Mayor said:
You can select the label tray from the print dialog - you should
also be able to edit the tray from the envelope/label dialog -
options.
You can do any of this by macro if you know the parameters - see the
examples for selectring alternative printers and/or trays at
http://www.gmayor.com/fax_from_word.htm

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

My web site www.gmayor.com

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

Hello Graham,

This macro code works beautifully. The labels are getting printed
the way it should be. I am still trying to overcome a printer word
problem.

In word during mail merge when you select avery shipping label
option the Laser and ink jet tray shows systemBypass to allow
manual feed.

When i run this macro the printer detects labels are being printed
and gives an error.I manually select auto paper size A4 and the data
is printed. I tried putting the label in the tray but it did not
work either. It flashes with Staybypass option. Is there any way a
default paper tray can be selected. We use printers in remote
location and are looking at getting a dedicated printer for this
purpose.

Can the user select the tray from which he wants to print might be
that way we can work around this problem.

:

To overcome the variables try the following:

1. The revised version below creates a new label document, so you
can print as many labels as you like on whatever printer you have
available.
2. The default label size is 5263, but you can insert another
number if you change this.
3. See 1
4. Run the macro from a toolbar button or better still on exit from
the last form field. The macro will then unlock and lock the form.
5. It doesn't matter what you call the form field bookmarks as long
as the names are echoed in the macro Text1 to 7 are what I used.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub






vandy wrote:
Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do
this.

1) the printer while printing labels is by Stack byPass as defualt
so the printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I
mention this here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the
normal print command can i do this with a macro.

4) when i protect the form and enter values i cannot run the
macro. I unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the
form feilds, is this correct.

Please bear with me if these questions are real basic but I am
beginning to understand the power of macros and its automation
capabilities and attempting to grasp the concept.


thanks





:

http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how
to extract data from a form, however, if the object of the
exercise is for a user to input data into the form and produce a
label, then the following macro will do that (with certain
provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label
Columns" GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _ ExtractAddress:=False,
SingleLabel:=True, _ Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are
using. To get the correct label name record a macro of printing
anything to that label format and extract the name from the
resulting macro. That label must be large enough to fit the text
as shown in the message prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you
have named the field bookmarks differently to give more
meaningful descriptions, you will have to change the bookmark
names Text1-7


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

My web site www.gmayor.com

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

vandy wrote:
Hello Doug,

Thanks for your reply. I have gone through the Auto Form
document and would require some help.

Bear with me I am not very good at macros and dont totally
understand the concept of bookmark. If I am not wrong Bookmark
gives you the location of each feild typed in.


With my limited knowlege i have created a form which has input
text feilds to store information of the user. I am attempting to
extract these values. I have named each text box form feild
with a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG
[ ]

TOT QTY [ ]

each square bracket representing a text form feild with
bookmarks for each feild. Now how to extract the values for
these once the user inputs them. The order of these entries do
not change. Based on the entries i have to create a product tag
for merging labels. Is this possible. How do i proceed from
here.


:

You would have to advise how the data is arranged in the
reports, is the data always arranged in that way, etc. before
anyone could suggest a macro to you.

You might want to think however about designing the reports so
that the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself
of my services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values
from a word document and create a label tag out of it.

I have an inspection report which has project data like
Project desc, project no, Component desc, Dwg no input. I
have to extract this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which
extracts data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to
want to extract information from a document and create a
label from that information? That
being the case, what is the information and how will the
macro recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked will
merge specific selected feilds from a word document and
create a label tag.


I want to know if this can be automated and done. Ideally
the user should be prompted for what to enter and based on
his
 
G

Graham Mayor

You have to walk before you can run ;)

First clean up the mess from the crash -
http://www.gmayor.com/what_to_do_when_word_crashes.htm

You are going wrong by using the wrong bit of macro code. The one you have
used intercepts the envelope/label dialog. The posted macro has already used
that and the label has been created. All you need is to set the printer and
tray and pop up the print dialog.

Your modifications seem to suggest that the same printer is used throughout.
That being the case there is no need to change it. You can change the Tray
(are you sure that "Drawer 1" is the correct command? Record the action in a
temporary macro if you are not sure) and change it back. The additions below
pop up the print dialog so you can print as many labels as required or
change the tray further if required.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim sTray As String
Dim sName As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'get the filename of the form document
sName = ActiveDocument.FullName
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel, Address:=sLayout

'Print the labels
sTray = Options.DefaultTray
Options.DefaultTray = "Drawer 1"
Dialogs(wdDialogFilePrint).Show
Options.DefaultTray = sTray
'Switch back to the form document
Windows(sName).Activate

'Reprotect the form document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Hello Graham,

Thanks for the document giving me an option for selecting the tray. I
am new woking with macros and have attempted to add the code with the
exisiting macro you gave me.
I am running into run time errors.

I am getting the users input to print the labels and assuming that
this macro will print from drawer 1 thus choosing the tray and if not
than it print out from drawer 2.



Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

Dim sCurrentPrinter As String
Dim sTray As String
Dim sQuery As String

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If



sQuery = MsgBox("Print Labels?", vbYesNo, "Labels")
If sQuery = vbYes Then 'Answer is print labels

ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the
required printer

Options.DefaultTray = "Drawer 1" 'set labels to Tray 1
End If

If sQuery = vbNo Then 'Answer is regular document
ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the
required printer
Options.DefaultTray = "Drawer 2" 'Set labels to Tray 2
End If

With Dialogs(wdToolsEnvelopesAndLabels)
sCurrentPrinter = ActivePrinter 'Save the current printer
sTray = Options.DefaultTray 'Save the current tray
'ask the user whether labels are required
.DoNotSetAsSysDefault = True
.Execute
Dialogs(wdDialogToolsEnvelopesAndLabels).Show 'Pop up the wizard
dialog ActivePrinter = sCurrentPrinter 'Put the printer back as it
was at the start Options.DefaultTray = sTray 'Put the tray back as it
was at the start DoNotSetAsSysDefault = True
.Execute
End With
End Sub

window shuts down and word autosaves my document. Where am i going
wrong.

Thanks for the help.


Graham Mayor said:
You can select the label tray from the print dialog - you should
also be able to edit the tray from the envelope/label dialog -
options.
You can do any of this by macro if you know the parameters - see the
examples for selectring alternative printers and/or trays at
http://www.gmayor.com/fax_from_word.htm

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

My web site www.gmayor.com

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

Hello Graham,

This macro code works beautifully. The labels are getting printed
the way it should be. I am still trying to overcome a printer word
problem.

In word during mail merge when you select avery shipping label
option the Laser and ink jet tray shows systemBypass to allow
manual feed.

When i run this macro the printer detects labels are being printed
and gives an error.I manually select auto paper size A4 and the data
is printed. I tried putting the label in the tray but it did not
work either. It flashes with Staybypass option. Is there any way a
default paper tray can be selected. We use printers in remote
location and are looking at getting a dedicated printer for this
purpose.

Can the user select the tray from which he wants to print might be
that way we can work around this problem.

:

To overcome the variables try the following:

1. The revised version below creates a new label document, so you
can print as many labels as you like on whatever printer you have
available.
2. The default label size is 5263, but you can insert another
number if you change this.
3. See 1
4. Run the macro from a toolbar button or better still on exit from
the last form field. The macro will then unlock and lock the form.
5. It doesn't matter what you call the form field bookmarks as long
as the names are echoed in the macro Text1 to 7 are what I used.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub






vandy wrote:
Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do
this.

1) the printer while printing labels is by Stack byPass as defualt
so the printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I
mention this here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the
normal print command can i do this with a macro.

4) when i protect the form and enter values i cannot run the
macro. I unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the
form feilds, is this correct.

Please bear with me if these questions are real basic but I am
beginning to understand the power of macros and its automation
capabilities and attempting to grasp the concept.


thanks





:

http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how
to extract data from a form, however, if the object of the
exercise is for a user to input data into the form and produce a
label, then the following macro will do that (with certain
provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label
Columns" GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _ ExtractAddress:=False,
SingleLabel:=True, _ Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are
using. To get the correct label name record a macro of printing
anything to that label format and extract the name from the
resulting macro. That label must be large enough to fit the text
as shown in the message prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you
have named the field bookmarks differently to give more
meaningful descriptions, you will have to change the bookmark
names Text1-7


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

My web site www.gmayor.com

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

vandy wrote:
Hello Doug,

Thanks for your reply. I have gone through the Auto Form
document and would require some help.

Bear with me I am not very good at macros and dont totally
understand the concept of bookmark. If I am not wrong Bookmark
gives you the location of each feild typed in.


With my limited knowlege i have created a form which has input
text feilds to store information of the user. I am attempting to
extract these values. I have named each text box form feild
with a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG
[ ]

TOT QTY [ ]

each square bracket representing a text form feild with
bookmarks for each feild. Now how to extract the values for
these once the user inputs them. The order of these entries do
not change. Based on the entries i have to create a product tag
for merging labels. Is this possible. How do i proceed from
here.


:

You would have to advise how the data is arranged in the
reports, is the data always arranged in that way, etc. before
anyone could suggest a macro to you.

You might want to think however about designing the reports so
that the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself
of my services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values
from a word document and create a label tag out of it.

I have an inspection report which has project data like
Project desc, project no, Component desc, Dwg no input. I
have to extract this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which
extracts data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to
want to extract information from a document and create a
label from that information? That
being the case, what is the information and how will the
macro recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked will
merge specific selected feilds from a word document and
create a label tag.


I want to know if this can be automated and done. Ideally
the user should be prompted for what to enter and based on
his
 
G

Graham Mayor

You have to walk before you can run ;)

First clean up the mess from the crash -
http://www.gmayor.com/what_to_do_when_word_crashes.htm

You are going wrong by using the wrong bit of macro code. The one you have
used intercepts the envelope/label dialog. The posted macro has already used
that and the label has been created. All you need is to set the printer and
tray and pop up the print dialog.

Your modifications seem to suggest that the same printer is used throughout.
That being the case there is no need to change it. You can change the Tray
(are you sure that "Drawer 1" is the correct command? Record the action in a
temporary macro if you are not sure) and change it back. The additions below
pop up the print dialog so you can print as many labels as required or
change the tray further if required.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim sTray As String
Dim sName As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'get the filename of the form document
sName = ActiveDocument.FullName
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel, Address:=sLayout

'Print the labels
sTray = Options.DefaultTray
Options.DefaultTray = "Drawer 1"
Dialogs(wdDialogFilePrint).Show
Options.DefaultTray = sTray
'Switch back to the form document
Windows(sName).Activate

'Reprotect the form document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Hello Graham,

Thanks for the document giving me an option for selecting the tray. I
am new woking with macros and have attempted to add the code with the
exisiting macro you gave me.
I am running into run time errors.

I am getting the users input to print the labels and assuming that
this macro will print from drawer 1 thus choosing the tray and if not
than it print out from drawer 2.



Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

Dim sCurrentPrinter As String
Dim sTray As String
Dim sQuery As String

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If



sQuery = MsgBox("Print Labels?", vbYesNo, "Labels")
If sQuery = vbYes Then 'Answer is print labels

ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the
required printer

Options.DefaultTray = "Drawer 1" 'set labels to Tray 1
End If

If sQuery = vbNo Then 'Answer is regular document
ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the
required printer
Options.DefaultTray = "Drawer 2" 'Set labels to Tray 2
End If

With Dialogs(wdToolsEnvelopesAndLabels)
sCurrentPrinter = ActivePrinter 'Save the current printer
sTray = Options.DefaultTray 'Save the current tray
'ask the user whether labels are required
.DoNotSetAsSysDefault = True
.Execute
Dialogs(wdDialogToolsEnvelopesAndLabels).Show 'Pop up the wizard
dialog ActivePrinter = sCurrentPrinter 'Put the printer back as it
was at the start Options.DefaultTray = sTray 'Put the tray back as it
was at the start DoNotSetAsSysDefault = True
.Execute
End With
End Sub

window shuts down and word autosaves my document. Where am i going
wrong.

Thanks for the help.


Graham Mayor said:
You can select the label tray from the print dialog - you should
also be able to edit the tray from the envelope/label dialog -
options.
You can do any of this by macro if you know the parameters - see the
examples for selectring alternative printers and/or trays at
http://www.gmayor.com/fax_from_word.htm

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

My web site www.gmayor.com

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

Hello Graham,

This macro code works beautifully. The labels are getting printed
the way it should be. I am still trying to overcome a printer word
problem.

In word during mail merge when you select avery shipping label
option the Laser and ink jet tray shows systemBypass to allow
manual feed.

When i run this macro the printer detects labels are being printed
and gives an error.I manually select auto paper size A4 and the data
is printed. I tried putting the label in the tray but it did not
work either. It flashes with Staybypass option. Is there any way a
default paper tray can be selected. We use printers in remote
location and are looking at getting a dedicated printer for this
purpose.

Can the user select the tray from which he wants to print might be
that way we can work around this problem.

:

To overcome the variables try the following:

1. The revised version below creates a new label document, so you
can print as many labels as you like on whatever printer you have
available.
2. The default label size is 5263, but you can insert another
number if you change this.
3. See 1
4. Run the macro from a toolbar button or better still on exit from
the last form field. The macro will then unlock and lock the form.
5. It doesn't matter what you call the form field bookmarks as long
as the names are echoed in the macro Text1 to 7 are what I used.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub






vandy wrote:
Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do
this.

1) the printer while printing labels is by Stack byPass as defualt
so the printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I
mention this here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the
normal print command can i do this with a macro.

4) when i protect the form and enter values i cannot run the
macro. I unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the
form feilds, is this correct.

Please bear with me if these questions are real basic but I am
beginning to understand the power of macros and its automation
capabilities and attempting to grasp the concept.


thanks





:

http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you how
to extract data from a form, however, if the object of the
exercise is for a user to input data into the form and produce a
label, then the following macro will do that (with certain
provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label Rows"
GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column", 1)
If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label
Columns" GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _ ExtractAddress:=False,
SingleLabel:=True, _ Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are
using. To get the correct label name record a macro of printing
anything to that label format and extract the name from the
resulting macro. That label must be large enough to fit the text
as shown in the message prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you
have named the field bookmarks differently to give more
meaningful descriptions, you will have to change the bookmark
names Text1-7


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

My web site www.gmayor.com

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

vandy wrote:
Hello Doug,

Thanks for your reply. I have gone through the Auto Form
document and would require some help.

Bear with me I am not very good at macros and dont totally
understand the concept of bookmark. If I am not wrong Bookmark
gives you the location of each feild typed in.


With my limited knowlege i have created a form which has input
text feilds to store information of the user. I am attempting to
extract these values. I have named each text box form feild
with a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG
[ ]

TOT QTY [ ]

each square bracket representing a text form feild with
bookmarks for each feild. Now how to extract the values for
these once the user inputs them. The order of these entries do
not change. Based on the entries i have to create a product tag
for merging labels. Is this possible. How do i proceed from
here.


:

You would have to advise how the data is arranged in the
reports, is the data always arranged in that way, etc. before
anyone could suggest a macro to you.

You might want to think however about designing the reports so
that the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself
of my services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values
from a word document and create a label tag out of it.

I have an inspection report which has project data like
Project desc, project no, Component desc, Dwg no input. I
have to extract this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which
extracts data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to
want to extract information from a document and create a
label from that information? That
being the case, what is the information and how will the
macro recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked will
merge specific selected feilds from a word document and
create a label tag.


I want to know if this can be automated and done. Ideally
the user should be prompted for what to enter and based on
his
 
G

Graham Mayor

Oops - triplicate - I don't know how that happened :(

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

My web site www.gmayor.com

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

Graham said:
You have to walk before you can run ;)

First clean up the mess from the crash -
http://www.gmayor.com/what_to_do_when_word_crashes.htm

You are going wrong by using the wrong bit of macro code. The one you
have used intercepts the envelope/label dialog. The posted macro has
already used that and the label has been created. All you need is to
set the printer and tray and pop up the print dialog.

Your modifications seem to suggest that the same printer is used
throughout. That being the case there is no need to change it. You
can change the Tray (are you sure that "Drawer 1" is the correct
command? Record the action in a temporary macro if you are not sure)
and change it back. The additions below pop up the print dialog so
you can print as many labels as required or change the tray further
if required.
Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim sTray As String
Dim sName As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'get the filename of the form document
sName = ActiveDocument.FullName
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout
'Print the labels
sTray = Options.DefaultTray
Options.DefaultTray = "Drawer 1"
Dialogs(wdDialogFilePrint).Show
Options.DefaultTray = sTray
'Switch back to the form document
Windows(sName).Activate

'Reprotect the form document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


Hello Graham,

Thanks for the document giving me an option for selecting the tray. I
am new woking with macros and have attempted to add the code with the
exisiting macro you gave me.
I am running into run time errors.

I am getting the users input to print the labels and assuming that
this macro will print from drawer 1 thus choosing the tray and if not
than it print out from drawer 2.



Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

Dim sCurrentPrinter As String
Dim sTray As String
Dim sQuery As String

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If



sQuery = MsgBox("Print Labels?", vbYesNo, "Labels")
If sQuery = vbYes Then 'Answer is print labels

ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the
required printer

Options.DefaultTray = "Drawer 1" 'set labels to Tray 1
End If

If sQuery = vbNo Then 'Answer is regular document
ActivePrinter = "\\numetServer\Canon5000ps downstairs" 'Set the
required printer
Options.DefaultTray = "Drawer 2" 'Set labels to Tray 2
End If

With Dialogs(wdToolsEnvelopesAndLabels)
sCurrentPrinter = ActivePrinter 'Save the current printer
sTray = Options.DefaultTray 'Save the current tray
'ask the user whether labels are required
.DoNotSetAsSysDefault = True
.Execute
Dialogs(wdDialogToolsEnvelopesAndLabels).Show 'Pop up the wizard
dialog ActivePrinter = sCurrentPrinter 'Put the printer back as it
was at the start Options.DefaultTray = sTray 'Put the tray back as it
was at the start DoNotSetAsSysDefault = True
.Execute
End With
End Sub

window shuts down and word autosaves my document. Where am i going
wrong.

Thanks for the help.


Graham Mayor said:
You can select the label tray from the print dialog - you should
also be able to edit the tray from the envelope/label dialog -
options.
You can do any of this by macro if you know the parameters - see the
examples for selectring alternative printers and/or trays at
http://www.gmayor.com/fax_from_word.htm

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

My web site www.gmayor.com

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


vandy wrote:
Hello Graham,

This macro code works beautifully. The labels are getting printed
the way it should be. I am still trying to overcome a printer word
problem.

In word during mail merge when you select avery shipping label
option the Laser and ink jet tray shows systemBypass to allow
manual feed.

When i run this macro the printer detects labels are being printed
and gives an error.I manually select auto paper size A4 and the
data is printed. I tried putting the label in the tray but it did
not work either. It flashes with Staybypass option. Is there any
way a default paper tray can be selected. We use printers in remote
location and are looking at getting a dedicated printer for this
purpose.

Can the user select the tray from which he wants to print might be
that way we can work around this problem.

:

To overcome the variables try the following:

1. The revised version below creates a new label document, so you
can print as many labels as you like on whatever printer you have
available.
2. The default label size is 5263, but you can insert another
number if you change this.
3. See 1
4. Run the macro from a toolbar button or better still on exit
from the last form field. The macro will then unlock and lock the
form. 5. It doesn't matter what you call the form field bookmarks as
long as the names are echoed in the macro Text1 to 7 are what I
used. Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel,
Address:=sLayout 'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub






vandy wrote:
Hello Graham,

Thanks a ton for the macros. I am facing some problems when i do
this.

1) the printer while printing labels is by Stack byPass as
defualt so the printer always gives me an error msg.

2) Reg. size
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _
ExtractAddress:=False, SingleLabel:=True, _

I would be using ( 4" X 2" ) 5263 avery std. labels should I
mention this here I foresee labels of different sizes used .

3)If i need to control the no of print copies as we see in the
normal print command can i do this with a macro.

4) when i protect the form and enter values i cannot run the
macro. I unprotect the form and run the macro.

5) i have assigned assigned bookmarks from Text1 to Text7 to the
form feilds, is this correct.

Please bear with me if these questions are real basic but I am
beginning to understand the power of macros and its automation
capabilities and attempting to grasp the concept.


thanks





:

http://gregmaxey.mvps.org/Extract_Form_Data.htm will show you
how to extract data from a form, however, if the object of the
exercise is for a user to input data into the form and produce a
label, then the following macro will do that (with certain
provisos)

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim iC, iR As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Choose the label position
Rows:
iR = InputBox("Print label on which row?", "Labels Row", 1)
If iR > 7 Then 'edit number to match label stock
MsgBox "There are only seven rows!", vbCritical, "Label
Rows" GoTo Rows:
End If
Columns:
iC = InputBox("Print label in which column?", "Labels Column",
1) If iR > 2 Then 'edit number to match label stock
MsgBox "There are only 2 columns!", vbCritical, "Label
Columns" GoTo Columns:
End If
'Print the label
Application.MailingLabel.PrintOut Name:="AE (2x7)",
Address:=sLayout, _ ExtractAddress:=False,
SingleLabel:=True, _ Row:=iR, Column:=iC
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub


http://www.gmayor.com/installing_macro.htm
The label pattern - here a custom label on my PC is
AE (2x7)
This name must be changed to match the label format you are
using. To get the correct label name record a macro of printing
anything to that label format and extract the name from the
resulting macro. That label must be large enough to fit the text
as shown in the message prompt.
Edit the macro to match your label format (rows and columns)
The fieldnames shown in f1 to f7 are the default names. If you
have named the field bookmarks differently to give more
meaningful descriptions, you will have to change the bookmark
names Text1-7


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

My web site www.gmayor.com

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

vandy wrote:
Hello Doug,

Thanks for your reply. I have gone through the Auto Form
document and would require some help.

Bear with me I am not very good at macros and dont totally
understand the concept of bookmark. If I am not wrong Bookmark
gives you the location of each feild typed in.


With my limited knowlege i have created a form which has input
text feilds to store information of the user. I am attempting
to extract these values. I have named each text box form feild
with a book mark.

PROJECT DESCRIPTION : [ ] COMPONENT [ ]

MPI NO [ ] DRAWING# [ ] REV NO [ ] ASSEMBLY DWG
[ ]

TOT QTY [ ]

each square bracket representing a text form feild with
bookmarks for each feild. Now how to extract the values for
these once the user inputs them. The order of these entries do
not change. Based on the entries i have to create a product tag
for merging labels. Is this possible. How do i proceed from
here.


:

You would have to advise how the data is arranged in the
reports, is the data always arranged in that way, etc. before
anyone could suggest a macro to you.

You might want to think however about designing the reports so
that the data extraction is facilitated.

See

http://www.mousetrax.com/techpage.html#autoforms


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail
yourself of my services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Graham,

Yes you are right. I need to extract specific field values
from a word document and create a label tag out of it.

I have an inspection report which has project data like
Project desc, project no, Component desc, Dwg no input. I
have to extract this information
and create a product tag. Is this possible.
I am not very good at macros. So any macro example which
extracts data to print will be of immense help.

Thanks in advance.


:

This doesn't sound much like a merge to me? You appear to
want to extract information from a document and create a
label from that information? That
being the case, what is the information and how will the
macro recognize it
from the document?

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

My web site www.gmayor.com

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

vandy wrote:
Hi All.

I have to create a mail merge button which when clicked
will merge specific selected feilds from a word document
and create a label tag.


I want to know if this can be automated and done. Ideally
the user should be prompted for what to enter and based on
his
 
G

Guest

Hi Graham,

Thanks a ton for your code. I have been trying different combinations all
day to get around the printer problem. As suggested I ran the printtray code
seperately and it is printing from "Drawer 1" without error. when i combine
it with the getcontent code the printer stalls and i have to physically undo
the stackbypass option and select LTR on the printer. The funny part is when
i go to select option button on the printer pop up i see default tray as
drawer 1.

Now the label sheet appears on a new document I am unable to delete labels
that i dont require. Since the same label is listed for the full page. I am
forced to give the print command to complete the macro. Any suggestions.
Thanks for all your help.
 
G

Graham Mayor

Separate the printing process from the label creation process. This will
allow you to edit the label document before you print it. If your recorded
printing macro works use that instead - but don't forget to add in the code
to return to the previous state.

Sub GetContent()
Dim f1, f2, f3, f4, f5, f6, f7, sLayout As String
Dim strLabel As String
Dim sName As String
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'get the filename of the form document
sName = ActiveDocument.FullName
'Get the field content
f1 = ActiveDocument.FormFields("Text1").Result
f2 = ActiveDocument.FormFields("Text2").Result
f3 = ActiveDocument.FormFields("Text3").Result
f4 = ActiveDocument.FormFields("Text4").Result
f5 = ActiveDocument.FormFields("Text5").Result
f6 = ActiveDocument.FormFields("Text6").Result
f7 = ActiveDocument.FormFields("Text7").Result
'assemble the content with associated text
sLayout = "PRODUCT DESCRIPTION " & f1 & " COMPONENT " & f2 _
& vbCr & "MPI No " & f3 & " DRAWING# " & f4 _
& " REV NO " & f5 & " ASSEMBLY DWG " & f6 _
& vbCr & "TOT QTY " & f7
'Pick the label type
strLabel = InputBox("Label stock number?", "Labels", 5263)
'Create the label
Application.MailingLabel.CreateNewDocument Name:=strLabel, Address:=sLayout
Windows(sName).Activate

'Reprotect the form document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub

Sub PrintTheLabels()
'Print the labels
sTray = Options.DefaultTray
Options.DefaultTray = "Drawer 1"
Dialogs(wdDialogFilePrint).Show
Options.DefaultTray = sTray
Dim sTray As String
End Sub
 
G

Guest

Hi Graham,

I separated the printing process and tested it . It works.

When i run the getcontent macro seperately i am getting a run time error


Run-time error '5941' The requested member of the collection does not exist.

When i press debug. it points out to the command

windows(sName).Activate . Once i stop the degugger the new document with the
labels pops up and i can print the labels i need. How to get over this
problem now.

thanks for your patience
 
G

Graham Mayor

I cannot reproduce the problem in Word 2003. I have cross posted to the vba
forum to see if anyone has any ideas.
The command is supposed to re-call the form document so that it can be
protected again after the labels have been created.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

Thanks for all your help on the code. I have a lot to learn. This forum has
been extremely helpful and you have been very patient and supportive.
 

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