title: Why does VBA come out of debug mode when ".paste" method is used to paste data from cell in MS Excel to a cell in a MS Word table?
body: <p>The code below is intended to be used to copy a string from cells in an excel column sequentially <strong>(i=3 to 61)</strong>, find a directory folder containing many copies of the same .doc file , and paste each string into  the <strong>second</strong> row, <strong>first</strong> column of the first table in each .doc file.</p>
  <p>Problem:  The program un intentionally continues through loop and finishes running the rest of the code after executing the following line for the first time:</p>
  <pre><code>wddoc.Tables(1).Cell(2, 1).Range.Paste
  </code></pre>
  <p>This happens even though I am stepping into each line of code using F8 to reach this line of code. The code finishes running without having pasted anything into the remaining files in the directory. (The string in row 3 of the excel document was successfully pasted into <em><strong>plan template - Copy (10).docx</strong></em>  but the remaining strings were not pasted into the remaining files)</p>
  <p><strong>The code:</strong></p>
  <pre><code>Option Explicit
  Sub CopyExcelToWord(path As String)
  
  'variables----------------------------------------------------------------
  
  'Decare Object variables for the Word application and file or documentl
  Dim wdapp As Object, wddoc As Object, i As Integer
  
  'Declare a String variable for the directory root and current file in that directory
  Dim currentPath As String
  
  
  'main process----------------------------------------------------------
  
  'error handling is extremely important in making Excel work with Word
  On Error Resume Next
  'GetObject needs two parameters. The first is optional
  Set wdapp = GetObject(, &quot;Word.Application&quot;)
  If Err.Number = 429 Then
  Err.Clear
  'we create a new instance of MS Word
  Set wdapp = CreateObject(&quot;Word.Application&quot;)
  End If
  
  'Our application is made visible
  
  wdapp.Visible = True
  
  currentPath = Dir(path, vbDirectory)
  
  For i = 3 To 61
  Do Until currentPath = vbNullString
  Debug.Print currentPath
  
  
  
          If Left(currentPath, 1) &lt;&gt; &quot;.&quot; And Left(currentPath, 1) &lt;&gt; &quot;&quot; Then
          Debug.Print path &amp; currentPath
             
              Sheet1.Range(Cells(i, 2), Cells(i, 2)).Copy
              'we activate our MS Word instance
              wdapp.Activate
              Set wddoc = wdapp.Documents(path &amp; currentPath)
              If wddoc Is Nothing Then Set wddoc = wdapp.Documents.Open(path &amp; currentPath)
              wddoc.Activate
              wddoc.Tables(1).Cell(2, 1).Range.Paste
              'Free alocated memory and close
              wdapp.Quit
              Set wddoc = Nothing
              Set wdapp = Nothing
          'The following line of code removes the cell selection in Excel
          Application.CutCopyMode = False
          currentPath = Dir()
          Else
          
          currentPath = Dir()
          
          End If
  
  
             
  Loop
  
  
  Next
  End Sub
  </code></pre>
  <p><strong>The print ( I have placed a '</strong>...<strong>' where I have omitted a section of the path ):</strong></p>
  <blockquote>
  <p>.
  .
  ..
  .
  plan template - Copy (10).docx
  L
  C:**...**\ plan template - Copy (10).docx</p>
  </blockquote>
  <p>The program runs through the rest of code unintentionally. The string in row 3 of the excel document was successfully pasted into <em><strong>plan template - Copy (10).docx</strong></em> and but the remaining strings were not pasted into the remaining files )</p>
  <blockquote>
  <p>plan template Copy (11).docx
  L
  C:*<em>...**\plan template - Copy (11).docx
  Lesson plan template - Copy (12).docx
  L
  C:*</em>...<strong>\plan template -Copy (12).docx
  plan template - Copy (13).docx
  L
  C:**...</strong>\ plan template -
  L
  <strong>...</strong>
  C:*<em>...**\plan template - Copy (9).docx
  Lesson plan template.docx
  L
  C:*</em>...**\plan template.docx</p>
  </blockquote>