FormatConditions in Excel 2007

My software produces an Excel spreadsheet and then formats it.  Upgrading from 2003 to 2007 broke the code pretty badly and the only thing left to fix seems to be the conditional formatting that the software adds to the spreadsheet, but I am stuck.

The code below breaks with the error:  "Method not found: 'Microsoft.Office.Interop.Excel.FormatCondition Microsoft.Office.Interop.Excel.FormatConditions.Add(Microsoft.Office.Interop.Excel.XlFormatConditionType, System.Object, System.Object, System.Object)'."  IntelliSense makes it appear that I am doing everything correctly.  How do I fix this?

Thanks in advance!

Pigparent
Dim oFormatCond1 As Excel.FormatCondition
.
.
.
oFormatCond1 = CType(oRange.FormatConditions.Add( _
                Excel.XlFormatConditionType.xlCellValue, _
                Excel.XlFormatConditionOperator.xlEqual, _
                Formula1:="=""Balanced"""), Excel.FormatCondition)

Open in new window

LVL 1
pigparentAsked:
Who is Participating?

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

x
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.

pigparentAuthor Commented:
PS -- I am using VS2008.
CodeCruiserCommented:
FormatCondition is valid in Excel 2007. There seems to be some other problem

http://msdn.microsoft.com/en-us/library/bb223827.aspx
pigparentAuthor Commented:
Yes, Intellisense indicated that it was still valid but it simply quit working once Office 2007 was installed.  I am using v11.0.0.0 of the interop.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

CodeCruiserCommented:
Interop version is the problem here. You are supposed to use correct interop library with each version of office.

If not that, the other option is to go dynamic. Instead of using static classes, create dynamic objects like

Dim app as Object = Marshal.GetActiveObject("Word.Application")

This would get you word application but

1) You will loose intellisense
2) You would be prone to errors as the method and property names would be evaluated at runtime not design time.
pigparentAuthor Commented:
If I have Office 2003 and Office 2007 users, which would be the correct interop version to use?  I am loathe to use late binding for many reasons, most of which you named.  If I am forced to do it I can (after researching; I never have done it that way before) but it didn't look like it would work any better.
CodeCruiserCommented:
To support both office 2003 and office 2007, you need to use both v11 and v12 of the PIAs. You would then need to add logic to execute different code depending on the version of Office installed.

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
pigparentAuthor Commented:
CodeCruiser, I promise you that I have tried using v12 and it didn't work.  I promise.  But I just tried it and it worked perfectly....go figure.  I only have two users on Office 2003 and they work in our Technology area so I can force them to upgrade!  Thanks for all of your help!
pigparentAuthor Commented:
Thanks again!
CodeCruiserCommented:
Glad that your problem is sorted :-)
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.