Excel Interface

mcguirepm
01-07-2005, 01:39 PM
I have a program that was originally written in VB5.0 that openned and manipulated several Excel spreadsheets. This worked tremendously well. :)

I have now imported this program into VB.Net and I am running into an error I can't seem to get around.

Dim MyFile as String
Dim AppExcel As Excel.Application

MyFile = Dir("T:\BOMS\masters\TS1500-140 Helix Curve Calc.*.xls")

AppExcel = CreateObject("Excel.Application")
AppExcel.Workbooks.Open(Filename:="T:\BOMS\masters\" & MyFile)

If AppExcel.Sheets("Frame Assembly 020950 Cut List".Range ("UpXMemMatl")) = "031503-49-38" Then
Do Something
Else
Do something Different
End If
.
.
.

I get the following error when I hit the IF statement:
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from type 'Range' to type 'String' is not valid.

Any insights would be appreciated.

Pat

rick_deacha
01-07-2005, 01:43 PM
I believe that here is the problemIf AppExcel.Sheets("Frame Assembly 020950 Cut List".Range ("UpXMemMatl")) = "031503-49-38" ThenShould beIf AppExcel.Sheets("Frame Assembly 020950 Cut List").Range ("UpXMemMatl").Value = "031503-49-38" ThenFollowing this syntaxis Sheets("Name of Sheet").Range("Name of Range").Value

mcguirepm
01-07-2005, 01:58 PM
:chuckle: Boy do I feel dumb. I had the .Value on every other line of code, but that one.

Thanks!

rick_deacha
01-07-2005, 02:00 PM
Actually the .Value was a plus... the main trouble was the missplaced parenthesis("Frame Assembly 020950 Cut List".Range ("UpXMemMatl"))and("Frame Assembly 020950 Cut List").Range ("UpXMemMatl")

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum