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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Just lose the brackets

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

Open in new window

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:

Rory ArchibaldCommented:
Shouldn't that be:
oExcel.WorkSheets("sheetname").Range("B1:B10")... etc


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.