By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,985 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,985 IT Pros & Developers. It's quick & easy.

HTML Text paste in Excel 2007 programmatically (VB2005)

P: 2
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
  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
May 6 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.