OK,
I think that this is a good start. Almost everything is automated and one click does the entire merge, but I need some help:
1. On the RIR (Master Sheet), if the row is blank, you should not be able to put an X in column A to send that (blank) row to the Label sheet.
2. The code that send the rows to the Labels sheet sends over some columns that I don't need for the labels. Only the light-blue headered columns are needed, but the code sends the entire range to the Labels sheet.
3. Probably more for the Word forum, but:
a) The code opens the Word template, does the Merge, creates a new sheet with the merged data, but then leaves the template open. The template should be closed after the new sheet is created.
b) I see alot about Error 429 and multiple instances of Word, so maybe I need some error-checking for that. (It works fine now, but I don't want it to break because of that.)
Here's the code for copying the X'ed rows to the Labels sheet:
Private Sub CommandButton1_Click()
Dim ce As Range
For Each ce In Range("A8:A" & Cells(Rows.Count, 1).End(xlUp).Row)
If Not IsEmpty(ce) Then
With Sheets("Labels")
.Unprotect "SECRET"
.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Resize(1, 22).Value = Range(ce, ce.Offset(0, 22)).Value
ce.ClearContents
.Select
.Protect "SECRET"
End With
End If
Next ce
End Sub
Here's the code for the button on the Labels sheet for the merge process:
Private Sub CommandButton2_Click()
Application.ScreenUpdating = True
Application.DisplayAlerts = False
'Opens Word doc
Set wordApp = New Word.Application
wordApp.Visible = True
wordApp.Documents.Open ThisWorkbook.Path & "\Label Template.doc"
With wordApp
'Use Excel to do the Mail Merge
.ActiveDocument.MailMerge.OpenDataSource Name:= _
ThisWorkbook.Path & "\TagLabelMaker R2.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="" _
, SQLStatement:="SELECT * FROM `Labels$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
'Display the Merged document
With .ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End With
End Sub
That's all for now. If anyone has a chance to look at this, I would appreciate the help!
Respectfully,
Lost
Bookmarks