Microsoft Office Tutorials and References
In Depth Information
Creating Word Labels from an Excel Recipient List
'Variable declaration for labels¶
Dim intCols As Integer¶
Dim intRows As Integer¶
Dim totCols As Integer¶
Dim totRows As Integer¶
Dim sngMaxDim As Single¶
Dim sngMinDim As Single¶
Dim tblIndex As Integer¶
On Error GoTo ErrHandler¶
'Working in active worksheet¶
Set objSht = Excel.ActiveSheet¶
'Set Data Range¶
With objSht¶
Set objRng = .Range(.Cells(2, 1), _¶
.Cells(65536, 1).End(xlUp))¶
End With¶
'Calculate total label count¶
lngQTY = Application.WorksheetFunction.Sum(objRng. _¶
Offset(, 6))¶
'Total job count to do (for progress bar)¶
'Opening Word Application = 1¶
'Preparing document = 1¶
'Creating empty labels = 1¶
'Writing into labels = lngQty¶
lngJobCount = lngQTY + 1 + 1 + 3¶
'Progress unit width on progress bar¶
'Completed width of progress bar is equal to¶
'background frame width¶
sngUnitWidth = Me.fraProgressBack.Width / lngJobCount¶
'Create Word application object¶
Set objApp = New Word.Application¶
'Update progress bar and status message¶
Call UpdateProgressBar("Creating Word Application", _¶
1 * sngUnitWidth)¶
'Start working in Word Application¶
With objApp¶
Call UpdateProgressBar("Preparing Word Document", _¶
2 * sngUnitWidth)¶
'Create new document in Word¶
'This is a temporary document object that¶
'we are using to create the new mailing label document¶
Set objDefDoc = .Documents.Add¶
'Create mailing label document¶
With .MailingLabel¶
.DefaultPrintBarCode = False¶
'wdPrinterManualFeed = 4¶
Set objDoc = .CreateNewDocument(Me.txtProduct.Text _¶
, "", "", 4)¶
'Close the temporary document¶
objDefDoc.Close False¶
End With¶
Search JabSto ::

Custom Search