I need help with a file path not opening in a MailMerge I am trying to write. I copied this code from a YouTube video and after some research on the 5174 error "Sorry can't find your file? Was it removed,etc?" I added the line about replacing Chr(13) but I'm still getting the error at the line
I would really appreciate any help you can give me!
VBA Code:
oDoc.MailMerge.OpenDataSource sPath
I would really appreciate any help you can give me!
VBA Code:
Public Sub LabelMerge()
' From https://www.youtube.com/watch?v=0nBcxc5zt1Q
Dim oWord As Word.Application, oDoc As Word.Document
Dim sPath As String, i As Integer, oHeaders As Range, bPrint As Boolean
Set oHeaders = Range("A1").CurrentRegion.rows(1)
sPath = ActiveWorkbook.FullName
sPath = Trim(sPath)
sPath = Replace(sPath, "Chr(13)", "")
If MsgBox("Print labels out (or send to new document)?", vbOKCancel) = vbOK Then bPrint = True
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
oWord.Visible = True
oDoc.MailMerge.MainDocumentType = wdMailingLabels
oWord.Dialogs(wdDialogLabelOptions).Show
oDoc.Activate
With oDoc.MailMerge.Fields
For i = 1 To oHeaders.Columns.Count
.Add oWord.Selection.Range, oHeaders.Cells(1, i)
oWord.Selection.TypeText " "
Next i
End With
oDoc.MailMerge.OpenDataSource sPath
oWord.WordBasic.mailmergepropagatelabel
oDoc.MailMerge.ViewMailMergeFieldCodes = False
oDoc.ActiveWindow.View.ShowFieldCodes = False
If bPrint = True Then
oDoc.MailMerge.Destination = wdSendToPrinter
oDoc.MailMerge.Execute
Else
oDoc.MailMerge.Destination = wdSendToNewDocument
oDoc.MailMerge.Execute
End If
Set oDoc = Nothing
Set oWord = Nothing
End Sub