title: Selecting only one row from a excel sheet (as part of mail merge)
body: <p>I am totally new to VBA and I am writing a code to mail merge data from each row in an excel sheet to a certain word document and save that document with name corresponding to the first cell value from each row.</p>
  
  <p><strong>Each row contains the information of a client. That is why I have to mailmerge each row info seperately.</strong></p>
  
  <p>So far the code works fine, but two problems I need to solve:</p>
  
  <p>1) <code>SQLStatement:="SELECT * FROM</code>Sheet1$<code>"</code> ends up mail merging info from all the rows in sheet during each iteration of the for loop (the loop iterates through each row). So what happens is that, each client's document includes data of other clients (excel rows) as well.</p>
  
  <p>2) The usual automation error unless I keep the source word document open.</p>
  
  <p><strong>So can someone please tell me how to select the info from only the row where the iteration has reached.</strong></p>
  
  <p>I tried<code>SQLStatement:="SELECT rw.row* FROM</code>Sheet1$<code>"</code> But it does not work</p>
  
  <p>Any help would be good. 
  The full code is:</p>
  
  <pre><code>Sub RunMerge()
  
  'booking document begins here
  
  Dim wd As Object
  Dim wdocSource As Object
  Dim activedoc
  Dim strWorkbookName As String
  Dim x As Integer
  Dim cdir As String
  Dim client As String
  
  Dim sh As Worksheet
  Dim rw As Range
  Dim rowcount As Integer
  
  Set sh = ActiveSheet
  For Each rw In sh.Rows
      If sh.Cells(rw.Row, 1).Value = "" Then
          Exit For
      End If
  
  
  
  cdir = "C:\Users\Kamlesh\Desktop\"
  client = Sheets("Sheet1").Cells(rw.Row + 1, 1).Value
  Dim newname As String
  newname = "Offer Letter - " &amp; client &amp; ".docx"
  
  
  On Error Resume Next
  Set wd = GetObject(, "Word.Application")
  If wd Is Nothing Then
      Set wd = CreateObject("Word.Application")
  End If
  On Error GoTo 0
  Const wdFormLetters = 0, wdOpenFormatAuto = 0
  Const wdSendToNewDocument = 0, wdDefaultFirstRecord = 1, wdDefaultLastRecord = -16
  
  Set wdocSource = wd.Documents.Open("C:\Users\Kamlesh\Desktop\master\Regen-booking.docx")
  
  strWorkbookName = ThisWorkbook.Path &amp; "\" &amp; ThisWorkbook.Name
  
  wdocSource.MailMerge.MainDocumentType = wdFormLetters
  
  wdocSource.MailMerge.OpenDataSource _
          Name:=strWorkbookName, _
          AddToRecentFiles:=False, _
          Revert:=False, _
          Format:=wdOpenFormatAuto, _
          Connection:="Data Source=" &amp; strWorkbookName &amp; ";Mode=Read", _
          SQLStatement:="SELECT * FROM `Sheet1$`"
  
  With wdocSource.MailMerge
      .Destination = wdSendToNewDocument
      .SuppressBlankLines = True
      With .DataSource
          .FirstRecord = wdDefaultFirstRecord
          .LastRecord = wdDefaultLastRecord
      End With
      .Execute Pause:=False
  End With
  
  wd.Visible = True
  wd.ActiveDocument.SaveAs cdir + newname
  'wdocSource.Close SaveChanges:=False
  'wd.Quit
  Set wdocSource = Nothing
  Set wd = Nothing
  
  
  Next rw
  
  End Sub
  </code></pre>
  
  <p>My Excel Sheet looks like this</p>
  
  <p><a href="https://i.stack.imgur.com/2fykR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2fykR.png" alt="enter image description here"></a></p>