2

I'm trying to get the values from Excel TextBoxes using VB.NET, but everything goes wrong. (errors like:" 'Forms' is not a member of Interop " OR "TextBos is not an Interface")

Any Ideas?

Here is my code:

Dim xlApp As Application
Dim xlWorkBooks As Workbooks 
Dim xlWorkBook As Workbook 
Dim xlWorkSheet As Worksheet 
Dim xlWorkSheets As Sheets 

Using Microsoft.Vbe.Interop.Forms.TextBox

    Dim tb As Forms.TextBox

    xlApp = New Application

    xlApp.DisplayAlerts = False

    xlWorkBooks = xlApp.Workbooks

    xlWorkBook = xlWorkBooks.Open("C:\Users\pw02318\Documents\UiPath\Accese\exemplu_formular.xlsm")

    'xlApp.Visible = True

    xlWorkSheets = xlWorkBook.Sheets

    xlWorkSheet = CType(xlWorkSheets("New Form"), Worksheet)

    For Each  shp As Shape In xlWorkSheet.Shapes

        Dim oo As OLEObject = CType(xlWorkSheet.OLEObjects(shp.Name), OLEObject)
        tb = CType(oo.Object, Microsoft.Vbe.Interop.Forms.TextBox)
        console.WriteLine(oo.Name.ToString + tb.Text)

    Next shp

 End Using
djv
  • 15,168
  • 7
  • 48
  • 72
Under_Ice
  • 147
  • 5

1 Answers1

2

You can read your excel file and put it in a data reader using ExcelDataReader.

first add OpenXml.Excel.Data to your references and import it in your code, then you can write as below:

    logDestination = Environment.CurrentDirectory & "\log.txt"

    Dim filePaths As String() = Directory.GetFiles(path, "*.xlsx")

    If filePaths.Length > 1 Then
        File.AppendAllText(logDestination, DateTime.Now & " -----> There Is More Than One xlsx File In The Path Folder" + Environment.NewLine)
    ElseIf filePaths.Length = 0 Then
        File.AppendAllText(logDestination, DateTime.Now & " -----> There Is No xlsx File In The Path" + Environment.NewLine)
        Environment.[Exit](0)
    End If

    Dim dt = New DataTable()

    Dim reader As var = New ExcelDataReader(filePaths(0), 1, True)

    dt.Load(reader)
Ehsan Zand
  • 350
  • 1
  • 15