DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Apr 2006
    Location
    Brisbane Australia
    Posts
    5

    browse a excel file then open from openFileDialog or FolderBrowserDialog

    hi
    iam new to vb and trying to create a front page for my excel program.
    I am trying to use a vb express form to browse for a excel file via a button then open the selected file.
    have been workin on this for 4 days now with out any luck.
    this is the code i have so far.
    i thought this would of been quite easy as vb & excel should work together!!
    Code:
    Option Explicit On
    
    Imports Microsoft.Office.Interop
    
    Public Class ufmTheEstimator
      
        Private moApp As Excel.Application
    
        Private Sub btnOpenExistingProject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenExistingProject.Click
    
            Dim myStream As IO.Stream
            Dim openFileDialog1 As New OpenFileDialog()
    
            openFileDialog1.InitialDirectory = "My Documents:\"
            openFileDialog1.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*"
            openFileDialog1.FilterIndex = 2
            openFileDialog1.RestoreDirectory = True
    
            If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                myStream = openFileDialog1.OpenFile()
                If Not (myStream Is Nothing) Then
                
    
    
    'THIS IS WHERE I NEED THE CODE TO OPEN THE SELECTED FILE( I THINK)
    
    
                    myStream.Close()
                End If
            End If
          
        End Sub
    
        Private Sub btnOpenNewProject_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenNewProject.Click
    
            Dim oXLApp As Excel.Application       'Declare the object variables
            Dim oXLBook As Excel.Workbook
    
            oXLApp = New Excel.Application 'Create a new instance of Excel
    
            'oXLBook = oXLApp.Workbooks.Add  'Add a new workbook
    
            oXLApp.Visible = True               'Show it to the user
    
            oXLBook = oXLApp.Workbooks.Open("c:\Jobs\WillmattRoofing-12.xls") 'Open an existing workbook
            oXLApp = Nothing
        End Sub
    the btnOpenExistingProject will browse for a existing file and the btnOpenNewProject will open a specific file.

    iam also haveing a problem with this line in the second sub "New Excel.Application" it needs declaring but i carnt work out how.

    any help appreicated
    cheers
    toe
    Last edited by toecutter; 04-15-2006 at 07:33 PM. Reason: spelling

Similar Threads

  1. Replies: 0
    Last Post: 10-24-2005, 03:40 PM
  2. file reader open for too long
    By manjusingh in forum Java
    Replies: 0
    Last Post: 04-24-2005, 10:33 AM
  3. wav file fade in out help
    By jase_dukerider in forum C++
    Replies: 2
    Last Post: 04-14-2005, 07:48 PM
  4. How to open a bmp file?
    By FrankWu in forum Java
    Replies: 0
    Last Post: 08-16-2002, 04:21 PM
  5. Test a file to see if it's open
    By JohnN in forum VB Classic
    Replies: 12
    Last Post: 05-08-2001, 04:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links