CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Excel

  1. #1
    Join Date
    Aug 1999
    Posts
    28

    Excel

    Is there a way to open up an Excel file within the excel application itself from VB.

    I would like to open a file (ie. Parts List.xls) from VB, but I want it to be in the Excel application, seperate from the VB app.

    Thanks - Ron Gregoire

    I hope I'm explaining it clearly.



  2. #2
    Join Date
    Apr 2001
    Posts
    3

    Re: Excel


    Is this something you want to shell or something to which you would like to retain control?
    Here are a few samples:


    ' Demonstrate four different methods of opening an Excel file
    ' The last three methods are similar in that they retain control of the application
    ' The first method shells the operation, thereby relinquishing control
    public Sub OpenExcelFile()
    Dim sFilename as string
    Dim sShell as string
    Dim dTask as Double

    ' Existing sample Workbook
    sFilename = "C:\Data\Excel\TestWorkbook.xls"

    ' Utilizes Shell
    sShell = Excel.Application.Path & "\" & "Excel.exe " & sFilename
    dTask = Shell(sShell, vbNormalFocus)

    ' Utilizes Workbook object
    Dim wkb as Workbook
    set wkb = Excel.Workbooks.Open(sFilename)
    wkb.Application.Visible = true
    MsgBox "wkb Application Open"
    wkb.Close
    set wkb = nothing

    ' Utilizes CreateObject
    Dim xl as Object
    set xl = CreateObject("Excel.Sheet")
    xl.Application.Workbooks.Open sFilename
    xl.Application.Visible = true
    MsgBox "xl Application Open"
    set xl = nothing

    ' Utilizes Excel
    Excel.Workbooks.Open sFilename
    Excel.Application.Visible = true
    MsgBox "Excel Application Open"
    Call Excel.Workbooks.Close
    End Sub






  3. #3
    Join Date
    Aug 1999
    Posts
    28

    Re: Excel

    Utilizing WorkBook Method worked the best.

    Just wanted to say thanks for the help.


  4. #4
    Join Date
    Feb 2002
    Posts
    2

    Re: Excel

    can i know soding to open excel file?


  5. #5
    Join Date
    Feb 2002
    Posts
    2

    Re: Excel

    what is the function of shell acctually....


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