Results 1 to 6 of 6

Thread: Excel on a form

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Excel on a form

    I like flexgrids and have used them quite a bit but now I need something "more flexible" or powerful. Is it possible to place an actual Excel spreadsheet on a form?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    You may use OLE control.

    EDIT: or launch entire Excel and make it a child of your form. Let me know if you want to go this way so I can post some sample.
    Last edited by RhinoBull; May 4th, 2004 at 08:14 AM.

  3. #3

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    My idea is to have this spreadsheet on a separate form so I would then store in it the results from calculations performed on the main form. At the same time I could do statistics and make plots with those data using all the power built-in in Excel.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    For that purpose you don't even need to keep it open as you may simply set new values to cell(s) in the background.
    VB Code:
    1. Private Sub Command1_Click()
    2. '=======================
    3. Dim exl As Excel.Application
    4. Dim wbk As Workbook
    5. Dim wst As Worksheet
    6. Dim filename As String
    7. Dim varValue
    8.  
    9.     Set exl = New Excel.Application
    10.     exl.DisplayAlerts = False
    11.    
    12.     filename = App.Path & "\test.xls"
    13.     exl.Workbooks.Open filename
    14.    
    15.     Set wbk = exl.ActiveWorkbook
    16.     Set wst = wbk.ActiveSheet
    17.     varValue = "abc"
    18.    
    19.     wst.Range("A2").Value = varValue
    20.    
    21.     exl.Quit
    22.     Set wst = Nothing
    23.     Set wbk = Nothing
    24.     Set exl = Nothing
    25.  
    26. End Sub

  5. #5

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    That's a nice example, though I assume you must end the job with SaveWorkspace rather than QUit or else you'll lose the data.

    Thanks.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Oops, of course ...

    wst.Range("A2").Value = varValue
    wbk.Save
    ...

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