Dear sir I'm unable to get past the error 91 "Object variable or With block variable not set". How do I circumvent that?If the document you're opening is the mailmerge main document, rather than a file produced by a mailmerge, you don't even have one record - all you have is a mailmerge preview that has been disconnected from the data source. A mailmerge must be executed before a document with all records can come into existence. As it is, if your document is the mailmerge main document, you'd normally be getting an SQL prompt when you open it. Until that is answered, the merge can't execute. However, using Application.DisplayAlerts = False (not None) both prevents the SQL prompt and causes Word to disconnect it from the data source. Consequently, you need to both add the code to turn your document back into a mailmerge main document, supply the SQL string, then execute the merge. Try something along the lines of the following. As you'll see, it's a whole lot more involved than what you have.
Sub DoMailMerge() 'Note: A VBA Reference to the Word Object Model is required, via Tools|References Dim wdApp As New Word.Application, wdDoc As Word.Document Dim strWorkbookName As String: strWorkbookName = ThisWorkbook.FullName With wdApp 'Disable alerts to prevent an SQL prompt .DisplayAlerts = wdAlertsNone 'Open the mailmerge main document Set wdDoc = .Documents.Open("\\Sachin\c\CERTIFICATE\Loan from Bank.doc", _ ConfirmConversions:=False, ReadOnly:=True, AddToRecentfiles:=False) With wdDoc With .MailMerge 'Define the mailmerge type .MainDocumentType = wdFormLetters 'Define the output .Destination = wdSendToNewDocument .SuppressBlankLines = True 'Connect to the data source .OpenDataSource Name:=strWorkbookName, ReadOnly:=True, _ LinkToSource:=False, AddToRecentfiles:=False, _ Format:=wdOpenFormatAuto, _ Connection:="Provider=Microsoft.ACE.OLEDB.12.0;" & _ "User ID=Admin;Data Source=strWorkbookName;" & _ "Mode=Read;Extended Properties=""HDR=YES;IMEX=1"";", _ SQLStatement:="SELECT * FROM `Sheet1$`", _ SubType:=wdMergeSubTypeAccess With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With '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