For the life of me, I cannot fix this run time error-5273 (document name or path is not valid). on the code. Can someone with better eyes tell me what the issue is with the code below? Thank you.
Sub RunMerge()<br> <br> <br> Dim wd As Object<br> Dim wdocSource As Object<br> <br> <br> Dim strWorkbookName As String<br> <br> <br> On Error Resume Next<br> Set wd = GetObject(, "Word.Application")<br> If wd Is Nothing Then<br> Set wd = CreateObject("Word.Application")<br> End If<br> On Error GoTo 0<br> <br> <br> Set wdocSource = wd.Documents.Open("C:\Users\stephenc1\OneDrive - Carnival Corporation\Joiners_Docs\HR_Email_One_Docs\Visa Mail Merge.docx")<br> <br> <br> strWorkbookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name & "C:\Users\stephenc1\OneDrive - Carnival Corporation\Joiners_Docs\Seabourn Recruitment Tracker.xlsm"<br> <br> <br> wdocSource.MailMerge.MainDocumentType = wdFormLetters<br> <br> <br> wdocSource.MailMerge.OpenDataSource _<br> Name:=strWorkbookName, _<br> AddToRecentFiles:=False, _<br> Revert:=False, _<br> Format:=wdOpenFormatAuto, _<br> Connection:="Data Source=" & strWorkbookName & ";Mode=Read", _<br> SQLStatement:="SELECT * FROM `Visa$`"<br> <br> <br> With wdocSource.MailMerge<br> .Destination = wdSendToNewDocument<br> .SuppressBlankLines = True<br> With .DataSource<br> .FirstRecord = wdDefaultFirstRecord<br> .LastRecord = wdDefaultLastRecord<br> End With<br> .Execute Pause:=False<br> End With<br> <br> <br> wd.Visible = True<br> wdocSource.Close SaveChanges:=False<br> <br> <br> Set wdocSource = Nothing<br> Set wd = Nothing<br> <br> <br> End Sub<br>





Reply With Quote