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. Adding a comment in Excel

Adding a comment in Excel

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
9 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.
  • N Offline
    N Offline
    nvmoss
    wrote on last edited by
    #1

    I am developing a VB.NET application which dumps data and calculations to Excel. I am trying to write code to add a comment to a cell with the command EXL.DisplayCommentIndicator = Excel.XlCommentDisplayMode.xlCommentIndicatorOnly EXL.Range(x).AddComment(comment as text) No matter how I write the code I always get the following error: "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Exception from HRESULT: 0x800A03EC." Can anyone tell me what I am doing wrong? Thankks! nvmoss

    J 1 Reply Last reply
    0
    • N nvmoss

      I am developing a VB.NET application which dumps data and calculations to Excel. I am trying to write code to add a comment to a cell with the command EXL.DisplayCommentIndicator = Excel.XlCommentDisplayMode.xlCommentIndicatorOnly EXL.Range(x).AddComment(comment as text) No matter how I write the code I always get the following error: "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Exception from HRESULT: 0x800A03EC." Can anyone tell me what I am doing wrong? Thankks! nvmoss

      J Offline
      J Offline
      John Kuhn
      wrote on last edited by
      #2

      Of course, add a reference to the current project to the Excel library. Then, your code should appear something like this:

      Dim xl As New Excel.Application
      xl.Workbooks.Open("c:\000\book1.xls")
      xl.DisplayCommentIndicator = Excel.XlCommentDisplayMode.xlCommentIndicatorOnly
      xl.Range("Value1").AddComment("This is a comment")
      xl.ActiveWorkbook.Save()
      xl.Workbooks.Close()

      What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

      N 1 Reply Last reply
      0
      • J John Kuhn

        Of course, add a reference to the current project to the Excel library. Then, your code should appear something like this:

        Dim xl As New Excel.Application
        xl.Workbooks.Open("c:\000\book1.xls")
        xl.DisplayCommentIndicator = Excel.XlCommentDisplayMode.xlCommentIndicatorOnly
        xl.Range("Value1").AddComment("This is a comment")
        xl.ActiveWorkbook.Save()
        xl.Workbooks.Close()

        What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

        N Offline
        N Offline
        nvmoss
        wrote on last edited by
        #3

        Your suggestion doesn't work for me. Here is the code fragment I wrote: If CtrlP.Text <> "" Then Dim Com As String Dim ComRng As String Com = CType(CtrlP.Text, String) If IsNothing(lastcell) Then lastcellA = "B11" EXL.DisplayCommentIndicator = XlCommentDisplayMode.xlCommentIndicatorOnly ComRng = EXL.Range(lastcellA).Offset(0, 10).Address(rowabsolute:=False, columnabsolute:=False) EXL.Range(ComRng).AddComment(Com) End If Where EXL is the Excel application, lastcell is the last non-empty cell in the spreadsheet range in which I am dumping data, and lastcellA is the address of that cell. When I execute this code, I get the error message I copies in my original posting. What am I doing wrong? Thanks again for your help! nvmoss

        J 1 Reply Last reply
        0
        • N nvmoss

          Your suggestion doesn't work for me. Here is the code fragment I wrote: If CtrlP.Text <> "" Then Dim Com As String Dim ComRng As String Com = CType(CtrlP.Text, String) If IsNothing(lastcell) Then lastcellA = "B11" EXL.DisplayCommentIndicator = XlCommentDisplayMode.xlCommentIndicatorOnly ComRng = EXL.Range(lastcellA).Offset(0, 10).Address(rowabsolute:=False, columnabsolute:=False) EXL.Range(ComRng).AddComment(Com) End If Where EXL is the Excel application, lastcell is the last non-empty cell in the spreadsheet range in which I am dumping data, and lastcellA is the address of that cell. When I execute this code, I get the error message I copies in my original posting. What am I doing wrong? Thanks again for your help! nvmoss

          J Offline
          J Offline
          John Kuhn
          wrote on last edited by
          #4

          That's odd, my suggestion works for me; or, at least, it does run. You should realize that the stuff you're passing to the Address method won't work in VB.NET, those statements only work in Excel macros & VBA. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

          N 2 Replies Last reply
          0
          • J John Kuhn

            That's odd, my suggestion works for me; or, at least, it does run. You should realize that the stuff you're passing to the Address method won't work in VB.NET, those statements only work in Excel macros & VBA. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

            N Offline
            N Offline
            nvmoss
            wrote on last edited by
            #5

            Boy! I don't know what to do next. I changed computes last week. The new computer was loaded with Excel 2003, rather than the Excel 2002 that I had been using. I built this application onec before I realized that the Excel OM Library upgrade would be an issue. Ever since I switched back to Excel 2002, I have been getting a build error "The IBDE can't be found". It hasn't stopped the build. could this be related to the problem? As to the Address method, it returns the cell address correctly in VB.NET. Is this likely to cause a problem during run time? Thanks Again! nvmoss

            J 1 Reply Last reply
            0
            • J John Kuhn

              That's odd, my suggestion works for me; or, at least, it does run. You should realize that the stuff you're passing to the Address method won't work in VB.NET, those statements only work in Excel macros & VBA. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

              N Offline
              N Offline
              nvmoss
              wrote on last edited by
              #6

              John - I got the debug error message wrong in my last reply. It is "Interop.VBIDE was not found." Sorry! nvmoss

              1 Reply Last reply
              0
              • N nvmoss

                Boy! I don't know what to do next. I changed computes last week. The new computer was loaded with Excel 2003, rather than the Excel 2002 that I had been using. I built this application onec before I realized that the Excel OM Library upgrade would be an issue. Ever since I switched back to Excel 2002, I have been getting a build error "The IBDE can't be found". It hasn't stopped the build. could this be related to the problem? As to the Address method, it returns the cell address correctly in VB.NET. Is this likely to cause a problem during run time? Thanks Again! nvmoss

                J Offline
                J Offline
                John Kuhn
                wrote on last edited by
                #7

                Try adding and removing the reference to the Excel libs from your project. Other than that, I'm tapped out. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

                N 1 Reply Last reply
                0
                • J John Kuhn

                  Try adding and removing the reference to the Excel libs from your project. Other than that, I'm tapped out. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

                  N Offline
                  N Offline
                  nvmoss
                  wrote on last edited by
                  #8

                  I found a help file on this and thought you would like to know the answer. I had to find the Interop.VBIDE.dll file using windows explorer, then browse to the location in the Add Reference Dialog and add it to the project. The problem ws the the location had apparantly changes when I switched computers. Thanks again for your help! nvmoss

                  J 1 Reply Last reply
                  0
                  • N nvmoss

                    I found a help file on this and thought you would like to know the answer. I had to find the Interop.VBIDE.dll file using windows explorer, then browse to the location in the Add Reference Dialog and add it to the project. The problem ws the the location had apparantly changes when I switched computers. Thanks again for your help! nvmoss

                    J Offline
                    J Offline
                    John Kuhn
                    wrote on last edited by
                    #9

                    VS.NET generates an Interop.VBIDE.dll -- but which DLL does it reference and where is it located? What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

                    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