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. Is it possible to and edit an excel file from Visual Basic 2005?

Is it possible to and edit an excel file from Visual Basic 2005?

Scheduled Pinned Locked Moved Visual Basic
helpquestion
5 Posts 3 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.
  • G Offline
    G Offline
    Graham Latto
    wrote on last edited by
    #1

    I have written much code in VBA and now I wanted to explore Visual Basic 2005. My objective is to be able to open an excel file and to plug in a value in range ("A1") in the excel worksheet/workbook from a Visual Basic 2005 form. Any help/sample code would be tremendously appreciated. Thank you, Gray

    J P 2 Replies Last reply
    0
    • G Graham Latto

      I have written much code in VBA and now I wanted to explore Visual Basic 2005. My objective is to be able to open an excel file and to plug in a value in range ("A1") in the excel worksheet/workbook from a Visual Basic 2005 form. Any help/sample code would be tremendously appreciated. Thank you, Gray

      J Offline
      J Offline
      Justin Porteous
      wrote on last edited by
      #2

      Hope this helps, make sure you add your references. 'Open in Excel Dim myExcel As New Microsoft.Office.Interop.Excel.Application() Dim workBook As Microsoft.Office.Interop.Excel.Workbook Dim workSheet As New Worksheet Try If myExcel Is Nothing Then 'Failed to load Excell Object Else workBook = myExcel.Workbooks.Open("C:\myfile.xls", 0, True, 5, "", "", True, XlPlatform.xlWindows, "\t", False, False, 0, True, 1, 0) workSheet = workBook.ActiveSheet workSheet.Cells(1, 1) = "My value" workBook.Close() End If Catch ex As Exception 'Handle Exception End Try myExcel.Close()

      J 1 Reply Last reply
      0
      • J Justin Porteous

        Hope this helps, make sure you add your references. 'Open in Excel Dim myExcel As New Microsoft.Office.Interop.Excel.Application() Dim workBook As Microsoft.Office.Interop.Excel.Workbook Dim workSheet As New Worksheet Try If myExcel Is Nothing Then 'Failed to load Excell Object Else workBook = myExcel.Workbooks.Open("C:\myfile.xls", 0, True, 5, "", "", True, XlPlatform.xlWindows, "\t", False, False, 0, True, 1, 0) workSheet = workBook.ActiveSheet workSheet.Cells(1, 1) = "My value" workBook.Close() End If Catch ex As Exception 'Handle Exception End Try myExcel.Close()

        J Offline
        J Offline
        Justin Porteous
        wrote on last edited by
        #3

        Silly me, I forgot to save the document. To do this, use workSheet.Save or workSheet.SaveAs(fileName).

        G 1 Reply Last reply
        0
        • J Justin Porteous

          Silly me, I forgot to save the document. To do this, use workSheet.Save or workSheet.SaveAs(fileName).

          G Offline
          G Offline
          Graham Latto
          wrote on last edited by
          #4

          Thank you so much Justin! It works and I couldn't be more thankful. Again, thank you very much.

          1 Reply Last reply
          0
          • G Graham Latto

            I have written much code in VBA and now I wanted to explore Visual Basic 2005. My objective is to be able to open an excel file and to plug in a value in range ("A1") in the excel worksheet/workbook from a Visual Basic 2005 form. Any help/sample code would be tremendously appreciated. Thank you, Gray

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            Microsoft Office Interop has loads of good stuff. Justin's example is just the beginning of it.

            "I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon

            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