Trying an Excel Interop
-
I'm following along with this book and it says to add a reference library to Excel. In the book it has Excel 10, but I have Excel 11, which I suspect is irrelevant, but when I try to add a variable based upon Excel.Application, Visual Studio acts as if I haven't added the reference. Squiggly blue line under Excel.Application. The code below is the click event where the Excel.Application is called: Private Sub btnCalculate_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCalculate.Click Dim xlApp As Excel.Application Dim LoanPayment As Single xlApp = CType(CreateObject("Excel.Application"), Excel.Application) LoanPayment = xlApp.WorksheetFunction.Pmt _ (txtInterest.Text / 12, txtMonths.Text, txtPrincipal.Text) MsgBox("The monthly payment is " & _ Format(Abs(LoanPayment), "$#.##"), , "Mortgage") xlApp.Quit() End Sub End Class Not only do I have Office 2003, but I have Visual Studio Tools for the Microsoft Office System 2003 installed. Why isn't my reference working? Still coaxing software out of the can after all these years...
-
I'm following along with this book and it says to add a reference library to Excel. In the book it has Excel 10, but I have Excel 11, which I suspect is irrelevant, but when I try to add a variable based upon Excel.Application, Visual Studio acts as if I haven't added the reference. Squiggly blue line under Excel.Application. The code below is the click event where the Excel.Application is called: Private Sub btnCalculate_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCalculate.Click Dim xlApp As Excel.Application Dim LoanPayment As Single xlApp = CType(CreateObject("Excel.Application"), Excel.Application) LoanPayment = xlApp.WorksheetFunction.Pmt _ (txtInterest.Text / 12, txtMonths.Text, txtPrincipal.Text) MsgBox("The monthly payment is " & _ Format(Abs(LoanPayment), "$#.##"), , "Mortgage") xlApp.Quit() End Sub End Class Not only do I have Office 2003, but I have Visual Studio Tools for the Microsoft Office System 2003 installed. Why isn't my reference working? Still coaxing software out of the can after all these years...
I was able to use the book as a reference, but what I had to do to get this interop to work was a bit different: Private Sub btnCalculate_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCalculate.Click 1: Dim xlApp As Microsoft.Office.Interop.Excel.Application Dim LoanPayment As Single xlApp = CType(CreateObject("Excel.Application"), _ Microsoft.Office.Interop.Excel.Application) LoanPayment = xlApp.WorksheetFunction.Pmt _ (txtInterest.Text / 12, txtMonths.Text, txtPrincipal.Text) MsgBox("The Monthly Payment is " & _ Format(Abs(LoanPayment), "$#.##"), , "Mortgage") xlApp.Quit() End Sub End Class Why did I have to specify more precisely than the book suggested?
-
I was able to use the book as a reference, but what I had to do to get this interop to work was a bit different: Private Sub btnCalculate_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCalculate.Click 1: Dim xlApp As Microsoft.Office.Interop.Excel.Application Dim LoanPayment As Single xlApp = CType(CreateObject("Excel.Application"), _ Microsoft.Office.Interop.Excel.Application) LoanPayment = xlApp.WorksheetFunction.Pmt _ (txtInterest.Text / 12, txtMonths.Text, txtPrincipal.Text) MsgBox("The Monthly Payment is " & _ Format(Abs(LoanPayment), "$#.##"), , "Mortgage") xlApp.Quit() End Sub End Class Why did I have to specify more precisely than the book suggested?
Try putting this at the top of your code:
Imports Microsoft.Office.Interop
You should then be able to make it look just like the book. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Try putting this at the top of your code:
Imports Microsoft.Office.Interop
You should then be able to make it look just like the book. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Thanks Dave. The book was set up for use with Excel 2002, is there that big of a difference between Excel 10 and Excel 11? :) Still coaxing software out of the can after all these years...
-
Thanks Dave. The book was set up for use with Excel 2002, is there that big of a difference between Excel 10 and Excel 11? :) Still coaxing software out of the can after all these years...
Yes, there is. Starting with Office XP, Microsoft is putting out Primary Interop Assemblies that allow for easier integration with .NET Framework apps. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Yes, there is. Starting with Office XP, Microsoft is putting out Primary Interop Assemblies that allow for easier integration with .NET Framework apps. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Interesting. The book claims the lesson to be based upon using the Excel interop for Office XP. Since I'm in college, I went ahead and got Office Professional 2003 Academic. Skipped right over 2002/XP. ;P Additionally- I saw Visual Studio Tools for the Microsoft Office System 2003, and it was cheap, so I added that too. Oh, and I can't thank you enough. I'm learning tons! Still coaxing software out of the can after all these years...
-
Yes, there is. Starting with Office XP, Microsoft is putting out Primary Interop Assemblies that allow for easier integration with .NET Framework apps. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
The thing is that the book was referring to Office XP (2002). Whereas I was using Office 2003. My desktop is running Windows 2000 though. I used the object browser to look up the specific Excel interop I was looking for and saw the pathing didn't match the book, so I copied the full path and pasted it in. The "little blue squigglys" went away. I wonder what caused the discrepancy? Was it the book, or did I miss something somewhere? Still coaxing software out of the can after all these years...