• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 824
  • Last Modified:

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

0
braney
Asked:
braney
  • 2
1 Solution
 
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
 
Rory ArchibaldCommented:
Shouldn't that be:
oExcel.WorkSheets("sheetname").Range("B1:B10")... etc

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now