Microsoft Office Tutorials and References
In Depth Information
Creating Word Labels from an Excel Recipient List
'Fill in the label with data¶
'Following code line in this section¶
'determines if there are empty columns between labels¶
'***i Mod totCols) * (1 - (intCols <> intRows)) + 1***¶
objDoc.Tables(tblIndex).Cell(intLabelRow, _¶
(i Mod totCols) * (1 - (intCols <> intRows)) + 1) _¶
.Range.Text = objRow.Cells(1, 1).Value & vbCrLf & _¶
objRow.Cells(1, 2).Value & ", " & _¶
objRow.Cells(1, 3).Value & " " & _¶
objRow.Cells(1, 4).Value & vbCrLf & _¶
objRow.Cells(1, 5).Value & vbCrLf & _¶
objRow.Cells(1, 6).Value¶
If ((i + 1) Mod totCols) = 0 Then¶
'If there is no space between labels (vertically)¶
'then just increment 1 row¶
'Following comparison determines this in code line¶
'*** (intRows = totRows) ***¶
intLabelRow = intLabelRow + 1 - (intRows <> totRows)¶
If intLabelRow > objDoc.Tables(tblIndex).Rows.Count Then¶
tblIndex = tblIndex + 1¶
intLabelRow = 1¶
End If¶
End If¶
Next i¶
End If¶
'Decrease job count¶
j = j - 1¶
Next objRow¶
'Labels have been created¶
With objApp¶
'Goto top of the label document¶
.Selection.HomeKey 6¶
'Show Word application¶
.Visible = True¶
End With¶
'Inform user about completition¶
Me.lblStatus.Caption = "Done!"¶
ErrHandler:¶
If Err Then¶
'This error means that user entered a label product name¶
'that does not exist in Word's label products¶
If Err.Number = 5843 Then¶
MsgBox "Selected label product does not exist.", _¶
vbOKOnly + vbExclamation, "Error"¶
Else¶
'Other error¶
MsgBox "There is something wrong." & vbCrLf & _¶
Err.Number & "-" & Err.Description, _¶
vbOKOnly + vbExclamation, "Error"¶
End If¶
Cmb
Search JabSto ::




Custom Search