Programatically adding format condtions to Excel through VS

I'm programming an excel sheet using VS2008 in VB.Net and cannot get a line of code to work.

I'm trying to programatically add format conditions to a particular range in an excel sheet but I keep getting the same error: "Number of parameters specified does not match the expected number."

Usually I just create a macro in Excel and then see the code it produces - this gives me a pretty good indication of how to program in VB.Net. This time however it didn't seem to work.

I'm importing Microsoft.Office.Interop.Excel


oExcel.WorkSheet.Range("B1:B10").FormatConditions.Add(XlFormatConditionType.xlCellValue, XlFormatConditionOperator.xlLessEqual, "0")

Open in new window

braneyAsked:
Who is Participating?
 
Rory ArchibaldConnect With a Mentor Commented:
Shouldn't that be:
oExcel.WorkSheets("sheetname").Range("B1:B10")... etc

0
 
Hayes0Commented:
Just lose the brackets



Excel.WorkSheet.Range("B1:B10").FormatConditions.Add XlFormatConditionType.xlCellValue, XlFormatConditionOperator.xlLessEqual, "0"

Open in new window

0
 
braneyAuthor Commented:
Nope that's not it.

When I remove the brackets, it just adds them in automatically.

Besides, if you were to write:

Msgbox "Hello"

It would be exactly the same as:

Msgbox("Hello")
0
 
braneyAuthor Commented:
Sorry I should've clarified, oExcel is a name of a class instance I created that has a "worksheet" property. It does basically the same thing. Anyway, I played around with it a bit more and got it to work. It didn't have anything to do with the number of parameters, it was actually something to do with my class. I have no idea why the error was so unapplicable in this case.

Thanks anyway
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.