Macropod, you are amazing as usual. (You helped me 4 weeks ago for a Word merge and I appreciated it alot)
However, I need help once again.
This is the code I've used based on your link:
Code:
Sub RunMerge()
Dim strWorkbookName As String
strWorkbookName = ThisWorkbook.FullName
Dim wdapp As New Word.Application
Dim wddoc As Word.Document
With wdapp
'Disable alerts to prevent an SQL prompt
.DisplayAlerts = wdAlertsNone
'Open the mailmerge main document
Set wddoc = .Documents.Open("H:\Data\Steven\Master Prototype\Garanties et Options\Master - Garanties.docx")
With wddoc
.ActiveWindow.View.Type = wdNormalView
With .MailMerge
'Define the mailmerge type
.MainDocumentType = wdDirectory
'Connect to the data source
.OpenDataSource Name:=strWorkbookName, AddToRecentFiles:=False, _
Revert:=False, Format:=wdOpenFormatAuto, Connection:="Data Source=" _
& strWorkbookName & ";Mode=Read", SQLStatement:="SELECT * FROM 'Sheet1'"
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
'Define the output
.Destination = wdSendToNewDocument
'Excecute the merge
.Execute
'Disconnect from the data source
.MainDocumentType = wdNotAMergeDocument
End With
'Close the mailmerge main document
.Close False
End With
'Restore the Word alerts
.DisplayAlerts = wdAlertsAll
'Display Word and the document
.Visible = True
End With
End Sub
When I merge (aka run the code), a pop up comes up saying the excel file is already in use which is normal because my code is in the excel file itself which is indeed OPENED. I have to click on "Ok" everytime (meaning it'll open a copy in read only). Is there a way I can skip that step via a code? I've tried many things (legit 4 hours wasting my time) and I'm lost. (please view screenshot attached)
When I press ok, it merges and it's perfect so this is my only issue. I've uploaded the excel file, the master "merge" document word. Thank you so much in advance. In the excel file, I can't send it with the module in it because it's a csv and it deletes it automatically so please paste your code into the chat if you can, thanks a lot. I uploaded the CSV on a different site since yours doesn't support CSV uploads.
https://ufile.io/zfaja