Solved

How to use the CommonDialog to Navigate Open Filename from Excel97

Posted on 1998-04-22
3
188 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now