Results 1 to 3 of 3

Thread: Excel Automation

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    2

    Question

    I created a command button in VB6. In the click event I put the following code.

    Dim objExcel As Object
    Set objExcel = GetObject("C:\Dave.xls")
    objExcel.Application.Cells(1,1).Value = 7
    ((help))
    objExcel.Application.Quit
    Set objExcel = Nothing

    On the line that I wrote ((help)) I have been trying to find some code to save
    the file Dave.xls.
    My goal is to find some code to put in the command button such that when pressed
    it opens an Excel spreadsheet, writes 7 to cell 1,1, saves the file, the closes
    Excel.

    Thank you for taking the time to read this.
    Any help you can offer would be very much appreciated.

    Dave7.

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Sydney, Australia
    Posts
    74

    Wink

    try this
    (you will need to add the excel library in the project references)


    Private Sub Command1_Click()
    Dim appXL As Excel.Application
    Set appXL = CreateObject("Excel.Application")

    With appXL
    .Workbooks.Open FileName:="C:\temp.xls"
    .activesheet.Cells(1, 1).Value = 7
    .activeworkbook.save
    .quit
    End With

    Set appXL = Nothing

    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    2
    I will give it a try.
    Thank you very much for your time.

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