Solved

How to use the CommonDialog to Navigate Open Filename from Excel97

Posted on 1998-04-22
3
194 Views
Last Modified: 2012-08-13
I've recently switched to Office 97 and Windows NT 4 workstation and now can't seem to get the Common Dialog to bring up the OPEN FILES dialog to point and click filenames for VBA.  Even when I try it from a VB Form by adding it to the controls and then when I try to drop it I get an error?  Any ideas?
0
Comment
Question by:ProperRespect
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:bin_huwairib
ID: 1427430
What kind of error?
0
 

Accepted Solution

by:
LMSuporte earned 50 total points
ID: 1427431
In order to to get the name of the file you want to open you should use something like these code:

Private Function Ask4File()

'This function will return the file that the usr selected.
'If you need something more especific, you should try using the combination
'of the flags

    On Error GoTo SaveError
   
    With CommonDialog1
        'this will allow the user to press the CANCEL button
        .CancelError = True
        'this will set the INIT value for the file name
        .filename = "MyFile.WAV"
        'This will set the INIT value for the folder
        .InitDir = "C:\MyINITFolder"
        'This will define the formats you want people to open
        .Filter = "blablabla|*.DRS|Formato Dialogic  (*.ann, *.vox)|*.ann;*.vox|Wave  (*.wav)|*.wav|Todos os arquivos  (*.*)|*.*"
        'the title
        .DialogTitle = "Please enter the name of the file you want to open"
        'here you should check the VB help to see if you
        'need flags. You can combine them using the OR
        .Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt
        .ShowOPEN
    End With

    'If you want the complete path use COMMANDDIALOG1.FILENAME
    'if you want the file name only use COMMANDDIALOG1.FILETITLE
    Ask4File = CommonDialog1.filename
    Exit Function

SaveError:
    'Here you can disable some error you want, etc etc
    If Err.Number = XXXXX Then Exit Function
    MsgBox "Could not Open the file!" & CommonDialog1.filename & "Error description: " & Err.Description & "." & vbNewLine & "Error number: " & Err.Number, vbOKOnly, "An error has occoured"
End Function


0
 

Expert Comment

by:susmitashaikh
ID: 1427432
Private Sub CommandButton1_Click()
'OPENS THE FILE DAILOG BOX AND GETS THE FILE NAME DISPLAYS IN THE TEXT BOX

CommonDialog1.ShowOpen
TEXT1.Text = CommonDialog1.FileName
End Sub
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question