?
Solved

How to use the CommonDialog to Navigate Open Filename from Excel97

Posted on 1998-04-22
3
Medium Priority
?
196 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 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