Hi all!
I recorded a macro in Word using the mail merge wizard to print labels from an Excel file.
Here is the code I got from that:
Sub GenEtiq()
'
' GenEtiq Macro
'
'
ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels
ActiveDocument.MailMerge.OpenDataSource Name:= _
"Z:\Techniciens\SDPL\etiquettes\generation etiquette.xlsx", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=Z:\Techniciens\SDPL\etiquettes\generation etiquette.xlsx;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=37;Jet OLEDB" _
, SQLStatement:="SELECT * FROM `Sheet3$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:= _
"Departement"
Selection.TypeParagraph
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:="Salle"
Selection.TypeParagraph
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:= _
"Endroit"
Selection.TypeText Text:=" "
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:="Point"
Selection.WholeStory
Selection.Font.Size = 8
ActivePrinter = "\\beleprint001\BELEMDQA14"
With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End Sub
My question is: is there a way of making that a macro usable from the Excel file itself? I'm not familiar with VBA so I'm not sure where to start. I have a few tabs opened that are helping me with examples but it's still blurry..
Thank you in advance for your time and help.
Bookmarks