Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Trying an Excel Interop

Trying an Excel Interop

Scheduled Pinned Locked Moved Visual Basic
csharpvisual-studiocomtoolsquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tanstaafl28
    wrote on last edited by
    #1

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

    T 1 Reply Last reply
    0
    • T tanstaafl28

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

      T Offline
      T Offline
      tanstaafl28
      wrote on last edited by
      #2

      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?

      D 1 Reply Last reply
      0
      • T tanstaafl28

        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?

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • D Dave Kreskowiak

          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

          T Offline
          T Offline
          tanstaafl28
          wrote on last edited by
          #4

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

          D 1 Reply Last reply
          0
          • T tanstaafl28

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

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            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

            T 2 Replies Last reply
            0
            • D Dave Kreskowiak

              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

              T Offline
              T Offline
              tanstaafl28
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                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

                T Offline
                T Offline
                tanstaafl28
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups