Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GoExcel error when there is an empty cell

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
320 Views, 1 Reply

GoExcel error when there is an empty cell

How to prevent the GoExcel error when there is an empty cell?

The code below is an example.

 

Dim TestItem As String = "Test Item 3"
GoExcel.FindRow("C:\Temp\Test.xlsx", "Sheet1", "Item", "=", TestItem)
 MsgBox(GoExcel.CurrentRowValue("Value"))

 

ItemValue
Test Item 1Test Value 1
Test Item 2Test Value 2
  
Test Item 3Test Value 3
Tags (2)
Labels (1)
1 REPLY 1
Message 2 of 2
Ralf_Krieg
in reply to: Anonymous

Hello

 

Maybe one of the limitations of the integrated Excel engine. Try to use Excel itself instead:

 

Option Explicit On
AddReference "microsoft.office.interop.excel.dll"
Imports XL = Microsoft.Office.Interop.Excel

Private Sub Main
	Dim TestItem As String = "Test Item 3"
	MsgBox(FindValue("C:\Temp\Test.xlsx", "Sheet1", "Item", TestItem, "Value"),,"iLogic")
End Sub

Private Function FindValue(ByVal ExcelPath As String, ByVal ExcelSheet As String, ByVal SearchColumn As String, ByVal SearchString As String, ByVal ResultColumn As String) As String

    Dim oExcelApp As xl.Application = GetObject("","Excel.Application")
	If oExcelApp Is Nothing Then
		MsgBox("Unable to start Excel")
		Return Nothing
	End If
	
    Dim oWB As xl.Workbook = oExcelApp.Workbooks.Open(ExcelPath)
    Dim oWS As xl.Worksheet
    For Each oWS In oWB.Sheets
        If oWS.Name = ExcelSheet Then Exit For
    Next
    
	If oWS Is Nothing Then
		MsgBox("Sheet " & ExcelSheet & " not found. Abort")
		Return Nothing
	End If
	
	Dim colNo As Long=oExcelApp.WorksheetFunction.Match(SearchColumn, oWS.Rows(1), 0)
    Dim rowNo As Long=oExcelApp.WorksheetFunction.Match(SearchString, oWS.Columns(colNo), 0)
    colNo = oExcelApp.WorksheetFunction.Match(ResultColumn, oWS.Rows(1), 0)
	
    FindValue = oWS.Cells(rowNo, colNo).value
                
    oWB.Close (False)
    oExcelApp.quit
	
End Function

 


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report