Connecting Tech Pros Worldwide Forums | Help | Site Map

HTML Text paste in Excel 2007 programmatically (VB2005)

Newbie
 
Join Date: May 2008
Posts: 2
#1: May 6 '08
I'm getting problem in pasting HTML text in Excel 2007 whereas it is working fine in Excel 2003. The data pasted in excel 2007 is showing the the HTML code which is not desired. I need to have the text element as normal copy from HTML file in web browser is pasted in the opened excel cell (manual operation).
I'm enclosing the code I've written in the following :
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim sr As StreamReader = New StreamReader(WebBrowseSP.DocumentStream)
  3.         Dim xlAppOut As Excel.Application
  4.         Dim xlBookOut As Excel.Workbook
  5.         Dim xlSheet1 As Excel.Worksheet
  6.         xlAppOut = CreateObject("Excel.Application")
  7.         xlBookOut = xlAppOut.Workbooks.Add
  8.         xlSheet1 = xlBookOut.Worksheets.Item(1)
  9.         xlAppOut.Visible = True
  10.         Clipboard.Clear()
  11.         Dim strContent As String = GetSelection(WebBrowser1)
  12.         Clipboard.SetText(strContent)
  13.        xlSheet1.paste()
  14. End Sub
  15.  
  16. Private Function GetSelection(ByVal webBrowser As WebBrowser) As String
  17.         GetSelection = ""
  18.         Dim doc As IHTMLDocument2 = CType(webBrowser.Document.DomDocument, IHTMLDocument2)
  19.         Dim sel As IHTMLSelectionObject = doc.selection
  20.         Dim range As IHTMLTxtRange = CType(sel.createRange, IHTMLTxtRange)
  21.         GetSelection = range.htmlText
  22. End Function
  23.  

Reply