CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Location
    australia
    Posts
    2

    Combing Excel files with VB. URGENT!!!

    hey people im a newbie at VB programing and am requiring some help with a school project
    what i am requesting is that i need help with coding to be able add data from a form to an excel file. and also to be able to view excel files
    Thanks for any Help


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Combing Excel files with VB. URGENT!!!

    Here is an example how to write to excel

    Set oExcel = GetObject(App.Path & "\my.xls")

    oExcel.ActiveSheet.Range("A1").Value = "My Data"
    oExcel.ActiveSheet.Range("B2").Value = "MyData"
    oExcel.ActiveSheet.Range("C2").Value = "Value"

    oExcel.Application.Visible = True'this line will bring Excel to the top
    oExcel.Parent.Windows(1).Visible = True

    Set oExcel = Nothing ' Remove object variable.


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Combing Excel files with VB. URGENT!!!


    'another example, with early binding
    'most of this code was included in a question about excel
    'and cells formats here in Codeguru
    option Explicit
    'reference to:
    'microsoft excel 9.0 object lybrary

    private withevents xlApp as Excel.Application
    private withevents xlBook as Excel.Workbook
    private withevents xlSheet as Excel.Worksheet
    Dim Quitted as Boolean
    private Sub Command1_Click()

    If xlApp is nothing then
    set xlApp = new Excel.Application
    End If
    xlApp.Workbooks.Add
    If xlBook is nothing then
    set xlBook = xlApp.Workbooks(1)
    End If
    xlApp.Visible = true

    End Sub

    private Sub Command2_Click()
    If Not xlApp.ActiveWorkbook is nothing then
    If xlApp.Worksheets.Count = 0 then
    set xlSheet = xlApp.Worksheets.Add
    else
    set xlSheet = xlApp.Worksheets(1)
    End If
    else
    xlApp.Workbooks.Add
    set xlSheet = xlApp.Worksheets.Add
    End If
    xlSheet.Range("A1").Value = "bla"
    xlSheet.Range("A1").Font.Bold = true

    xlSheet.Columns("A:A").ColumnWidth = 17.43
    xlSheet.Rows("1:1").RowHeight = 15
    xlSheet.Range("A3").Select
    With xlApp.Selection.Interior
    .ColorIndex = 6
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    End With
    End Sub
    private Sub xlApp_WorkbookBeforeSave(byval Wb as Excel.Workbook, byval SaveAsUI as Boolean, Cancel as Boolean)
    xlApp.DefaultFilePath
    End Sub

    private Sub xlBook_BeforeClose(Cancel as Boolean)
    Quitted = true
    End Sub







    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Sep 2001
    Location
    australia
    Posts
    2

    Re: Combing Excel files with VB. URGENT!!!

    Thanks people for the coding supplied it should help me alot
    if you have any other sample coding that might be of some help it would be much appriciated

    thanks again
    New VB


  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Combing Excel files with VB. URGENT!!!

    see on the page
    Forum Index|FAQ|Edit Profile|Send Private|...|Search|...
    These are links. Click on
    |Search|
    and type in "Excel" (without quotes) as searched word. You will find a lot of code.

    Have a nice day,

    Cesare Imperiali

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured