Solved

How to use the CommonDialog to Navigate Open Filename from Excel97

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

770 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