Results 1 to 6 of 6

Thread: Using ShowOpen

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    Montreal, Quebec
    Posts
    400

    Using ShowOpen

    I found this code posted a few times on this site
    Code:
    Private Sub mnuFileOpen_Click ()
       ' CancelError is True.
       On Error GoTo ErrHandler
       ' Set filters.
       CommonDialog1.Filter = "All Files (*.*)|*.*|Text _
       Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
       ' Specify default filter.
       CommonDialog1.FilterIndex = 2
    
       ' Display the Open dialog box.
       CommonDialog1.ShowOpen 
       ' Call the open file procedure.
       OpenFile (CommonDialog1.FileName)
       Exit Sub
    
    ErrHandler:
    ' User pressed Cancel button.
       Exit Sub
    End Sub
    There is a call to OpenFile but the code is missing. Any idea what it could be?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    It could be anything. But if you want to put the text in a TextBox, this would work:

    VB Code:
    1. Private Sub OpenFile(strFileName As String)
    2. Dim iFF As Integer
    3.  
    4.   iFF = FreeFile() 'get available file number
    5.  
    6.   Open strFileName For Input As #iFF
    7.     Text1.Text = Input(LOF(iFF), 1)
    8.   Close #iFF
    9. End Sub

    That's assuming your TextBox is Text1.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    Probably something like:
    VB Code:
    1. Public Sub OpenFile(FileName as String)
    2.     Dim iFreeFile as Integer
    3.  
    4.     iFreeFile - FreeFile
    5.  
    6.     Open FileName For Input as #iFreeFile
    7.     '... input the records
    8.     Close #FreeFile
    9. End Sub
    (Adjusting the Access Mode as needed)

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I think we think alike, John.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    Montreal, Quebec
    Posts
    400
    Okay - I seem to be getting some sense of it. What I want to do is open an Excel file in my VB application (not visible). There is already a *.xls file open (loaded automatically when the program starts0 that I want to close and replace with the new file. Can I adapt the following and do I really need to make a call to a separate procedure?
    Code:
    Private Sub Form_Load()
    
        Set xlApp = New excel.Application
        'Set xlBook = xlApp.Workbooks.Open(App.Path & "\New ME Model #5e.xls")
        Set xlBook = xlApp.Workbooks.Open(App.Path & "\test.xls")
        Set xlSheetData = xlBook.Worksheets("input")
    
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    
        xlApp.Workbooks.Close
        xlApp.Quit
        Set xlApp = Nothing
        
    End Sub

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