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

Extract/convert string from XLS

P: 11
Here is my code:


Expand|Select|Wrap|Line Numbers
  1. Option Explicit On
  2. Option Strict Off
  3. Imports System.IO
  4. Imports System.Text
  5. Public Class Form1
  6. Public moApp As Object
  7.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8.         Try
  9.             moApp = CreateObject("Excel.Application")
  10.             moApp.Visible = False
  11.         Catch ex As Exception
  12.             MessageBox.Show(ex.Message, "VB/Office Guru™ Excel Late Binding VB.NET Automation FAQ", _
  13.             MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  14.         End Try
  15.     End Sub
  16.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  17.     Dim oWB As Object = moApp.Workbooks.Open(CurDir() & "\sample.xls")
  18.         moApp.Visible = False        
  19.     Dim listnames As String = File.ReadAllText(CurDir() & "\listofnames.txt")
  20.           Dim name as String    
  21.     name = oWB.Sheets("Sheet1").Cells(1, 1).Value
  22.     MsgBox(listanames.Contains(name))
  23. End Sub
  24. End Class
  25.  

Now, the problem is when I'm import cell from "*.xls" files an try to compare with other "normal" strings, it's just don't work! Massage box is alwayse "False".
I try with simple copy/paste from xls file in inputbox and they didn't work.
But when in inputbox write the same word/name manualy without extracting it from xls cell, they work! Msgbox is now "True"
I have impression that when extract string from XLS files, the strings are not the same like he was some other type of string, some other characters.
And I was doing check's puting "msgbox(name)" on some places and it is the equal string that it is in "listnames".
Try on Google, but nothing found. I'm thanking You in Advance if You solve this enigma!
Jun 11 '12 #1

✓ answered by Marko Danilovic

Problem solved:
It turned out that in fact these "*.xls" files are copied from the HTML files that have Chr(160) instead of standard spaces...
Now the program work fine.

Share this Question
Share on Google+
1 Reply


P: 11
Problem solved:
It turned out that in fact these "*.xls" files are copied from the HTML files that have Chr(160) instead of standard spaces...
Now the program work fine.
Jun 12 '12 #2

Post your reply

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