title: Pasting HTML table from clipboard to Excel worksheet with VB.NET Application
body: <p>I have a <code>DataTable</code> with 7000 rows and 60 columns, and I need to save it in an Excel file.</p>
  
  <p>Looping through the <code>DataTable</code> takes to much time, and the <a href="https://closedxml.codeplex.com/" rel="nofollow">ClosedXml</a> libary is raising an exception that I could not solve (for many weeks). So I have decided to create an HTML table from the <code>DataTable</code>, add it to the clipboard and paste it to the generic Excel file on the network.</p>
  
  <p><strong>the problem is that all the strings are written in Hebrew, and when the app is pasting the data all the strings don't encode properly, and Excel presents them as question marks.</strong></p>
  
  <p>Note: When I paste the data that the application set on the clipboard using my mouse the data is pasted like it should, without question marks. 
  Also I have tried to use all the Enum parameters of the <code>PasteSpecial()</code> method without success.
  Please see the relevant code parts I have added.</p>
  
  <pre><code> Public Function LoadDataTableToDivisinReport(ByVal d As DataTable, ByVal pathAndFileNameToSave As String, ByVal DbsheetNameToReplaceData As String, Optional ByVal pathToSaveImages As String = "") As Boolean
  ........
  
                  Dim t As Threading.Thread
                  t = New System.Threading.Thread(AddressOf createHtmlTableToClipBoard)
                  t.SetApartmentState(Threading.ApartmentState.STA)
                  t.Start()
                  ws.Range("a1").PasteSpecial(Excel.XlPasteType.xlPasteFormats)
  
  .........
  End Function
  
  
      Private Sub createHtmlTableToClipBoard()
  
          Dim b As New StringBuilder
          b.Append("&lt;table&gt;")
          b.Append("&lt;tr&gt;")
          For i = 0 To dd.Columns.Count - 1
              b.Append("&lt;th&gt;" &amp; dd.Columns(i).ColumnName &amp; "&lt;/th&gt;")
  
          Next
          b.Append("&lt;/tr&gt;")
  
  
  
          For j = 0 To dd.Rows.Count - 1
              b.Append("&lt;tr&gt;")
              For i = 0 To dd.Columns.Count - 1
                  b.Append("&lt;td&gt;")
                  b.Append(dd.Rows(j).Item(i).ToString)
                  b.Append("&lt;/td&gt;")
              Next
              b.Append("&lt;/tr&gt;")
          Next
  
          b.Append("&lt;/table&gt;")
  
          Clipboard.SetText(b.ToString())
  
      End Sub
  
      Private dd As DataTable
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  thanks to @ClearLogic comment the issue was solved, macros in the generic workbook was the cause for that behavior. Please see the discussion below @ClearLogic marked answer.</p>