Click here to Skip to main content
15,171,576 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I started Visual Basic in an API environment in Solidworks, moving over to visual studio Im noticing the methods are slightly different. I seem to have a problem and im not sure how far out my code is for Visual Studio, I'd appreciate any help.

On running the Code Below I get this Error ::

"Conversion from type 'Range to type Boolean' is not valid

Option Explicit On
Imports Microsoft.Office.Interop.Excel

Public Class MainForm
    Dim Excelobject As Object
    Dim ExcelBook As Object
    Dim ExcelSheet As Object
    Dim xlsh As Object
    Dim CopyCell As String

    Public Function GetExcellFilePath() As String
        GetExcellFilePath = "C:\Data\ItemBase.xlsx"
    End Function

    Public Sub OpenExcellDocument()
        Excelobject = GetObject(GetExcellFilePath)
        xlsh = Excelobject.ActiveSheet
        If Excelobject Is Nothing Then
            MsgBox("Could not Open ItemBase.xlsx")
        End If
    End Sub

    Public Sub Weapons(ByVal Row, ByVal Column)
        MsgBox(Row & Column)
        Do While (xlsh.Cells(Row, Column))
            CopyCell = xlsh.Cells(Row, Column).Value.ToString()
            Row = Val(Row + 1)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
        Weapons(3, 1)
    End Sub

End Class
You should always indicate the line of code where you have an error, explain the purpose of the code. Nobody wants a guesswork.

1 solution

You did not indication the line with the error, which is not nice, but xlsh.Cells(Row, Column) is incorrect. It requires Boolean as the loop requires condition. I have not idea what you try to achieve, probably you need foreach loop to traverse the range.

I see OP has fixed the problem -- all right.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900