I'm trying to create a template for labels. Here is what I would like to happen:
User opens template and is prompted for 6 pieces of information. User completes and clicks OK after each one.
Then, the last prompt asks how many labels, the user inputs the quantity of label, then the macro inputs the info the user has entered the number of times specified into the table in the template.
I've got pieces of it working, but not all. I'm new to VB and I'm getting frustrated. Can anyone give me guidance? Here is the code I've got so far.
Sub mCustomer()
vCustomer = InputBox(Prompt:="Please enter Customer's Name and click OK."
ActiveDocument.FormFields("Customer".Result = vCustomer
vIDOD = InputBox(Prompt:="Enter ID, OD and thickness and click OK."
ActiveDocument.FormFields("IDOD".Result = vIDOD
vPartNo = InputBox(Prompt:="Enter Part Number and click OK."
ActiveDocument.FormFields("PartNo".Result = vPartNo
vPkgQty = InputBox(Prompt:="Enter package quantity and click OK."
ActiveDocument.FormFields("PkgQty".Result = vPkgQty
vLotNo = InputBox(Prompt:="Enter lot number and click OK."
ActiveDocument.FormFields("LotNo".Result = vLotNo
vSpeeds = InputBox(Prompt:="Enter speeds and feeds and click OK."
ActiveDocument.FormFields("Speeds".Result = vSpeeds
End Sub
------------------------------
Sub AddLabels()
Dim l As Long
Dim lTotal As Long
Dim sInputText As Fields
Dim oTable As Table
On Error GoTo ErrHandler
lTotal = InputBox("How many labels"
If Len(lTotal) > 0 Then
If ActiveDocument.FormFields.Count > 0 Then
Set oTable = ActiveDocument.FormFields
For l = 1 To lTotal
oTable.Range.Cells(l).Range.Text = vCustomer
Next l
End If
End If
Set oTable = Nothing
Exit Sub
ErrHandler:
Select Case Err
Case 5941
'Number of cells in table is not
'sufficient, add new cells
oTable.Rows.Add
Resume
End Select
End Sub
User opens template and is prompted for 6 pieces of information. User completes and clicks OK after each one.
Then, the last prompt asks how many labels, the user inputs the quantity of label, then the macro inputs the info the user has entered the number of times specified into the table in the template.
I've got pieces of it working, but not all. I'm new to VB and I'm getting frustrated. Can anyone give me guidance? Here is the code I've got so far.
Sub mCustomer()
vCustomer = InputBox(Prompt:="Please enter Customer's Name and click OK."
ActiveDocument.FormFields("Customer".Result = vCustomer
vIDOD = InputBox(Prompt:="Enter ID, OD and thickness and click OK."
ActiveDocument.FormFields("IDOD".Result = vIDOD
vPartNo = InputBox(Prompt:="Enter Part Number and click OK."
ActiveDocument.FormFields("PartNo".Result = vPartNo
vPkgQty = InputBox(Prompt:="Enter package quantity and click OK."
ActiveDocument.FormFields("PkgQty".Result = vPkgQty
vLotNo = InputBox(Prompt:="Enter lot number and click OK."
ActiveDocument.FormFields("LotNo".Result = vLotNo
vSpeeds = InputBox(Prompt:="Enter speeds and feeds and click OK."
ActiveDocument.FormFields("Speeds".Result = vSpeeds
End Sub
------------------------------
Sub AddLabels()
Dim l As Long
Dim lTotal As Long
Dim sInputText As Fields
Dim oTable As Table
On Error GoTo ErrHandler
lTotal = InputBox("How many labels"
If Len(lTotal) > 0 Then
If ActiveDocument.FormFields.Count > 0 Then
Set oTable = ActiveDocument.FormFields
For l = 1 To lTotal
oTable.Range.Cells(l).Range.Text = vCustomer
Next l
End If
End If
Set oTable = Nothing
Exit Sub
ErrHandler:
Select Case Err
Case 5941
'Number of cells in table is not
'sufficient, add new cells
oTable.Rows.Add
Resume
End Select
End Sub