Programatically adding format condtions to Excel through VS

Posted on 2008-11-19
Last Modified: 2012-05-05
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

Question by:braney

    Expert Comment

    Just lose the brackets

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

    Open in new window


    Author Comment

    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:

    LVL 85

    Accepted Solution

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


    Author Comment

    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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
    This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
    This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now