Results 1 to 4 of 4

Thread: opening a workbook in excel with vb

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    montreal
    Posts
    13

    Question

    hi
    i want to open a workbook
    excel
    with
    vb but it doesn't work
    can you help with the code
    thanks you
    i did put that but it does not work
    Application.GetOpenFilename
    NewFile = ActiveWorkbook.Name
    thanks you

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655

    Wink

    The best way in my opinion is to create an instance of excel and tell it to open your file. Here is a sample, it opens the path "c:\test.xls" into excel when the button is clicked and then displays excel:

    Code:
    Private Sub Command1_Click()
    Set ex = CreateObject("Excel.Application")
    Set book = ex.Workbooks
    ex.Visible = True
    book.Open "c:\test.xls"
    End Sub
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3
    Lively Member
    Join Date
    Aug 2000
    Posts
    117
    It can be done in an even easier way
    <code>
    Private Sub Form_Load()
    Excel.Workbooks.Open ("C:\My Documents\Book5.xls")
    Excel.Application.Visible = True
    End Sub
    </code>

  4. #4
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    True but this will make your final product larger because you are including the excel runtime files in the references. If you know the end user will have excel, I'd use my way because it makes you product smaller. But it's more of a personal preferance than anything else.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

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