Solved

How to use the CommonDialog to Navigate Open Filename from Excel97

Posted on 1998-04-22
3
193 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…

830 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