COMMONDIALOG BOX

User avatar
sal21
PlatinumLounger
Posts: 4346
Joined: 26 Apr 2010, 17:36

COMMONDIALOG BOX

Post by sal21 »

Ho to select/open only a file with .exp in c:\mydir\

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: COMMONDIALOG BOX

Post by HansV »

Do you already have code for the CommonDialog?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4346
Joined: 26 Apr 2010, 17:36

Re: COMMONDIALOG BOX

Post by sal21 »

HansV wrote:
26 Feb 2022, 14:04
Do you already have code for the CommonDialog?
no...
never used

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: COMMONDIALOG BOX

Post by HansV »

Use something like

Code: Select all

    Dim strFile As String
    With CommonDialog1
        .Filter = "Exp Files (*.exp)|*.exp"
        .InitDir = "C:\MyDir"
        .ShowOpen
        If .FileName = "" Then
            MsgBox "No file selected!"
            Exit Sub
        End If
        strFile = .FileName
    End With
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4346
Joined: 26 Apr 2010, 17:36

Re: COMMONDIALOG BOX

Post by sal21 »

HansV wrote:
26 Feb 2022, 15:51
Use something like

Code: Select all

    Dim strFile As String
    With CommonDialog1
        .Filter = "Exp Files (*.exp)|*.exp"
        .InitDir = "C:\MyDir"
        .ShowOpen
        If .FileName = "" Then
            MsgBox "No file selected!"
            Exit Sub
        End If
       strFile = .FileName 
    End With
HUMMMM...
but strFile = .FileName contain dir & filename...
in other var i need only the name of file

:clapping:

User avatar
sal21
PlatinumLounger
Posts: 4346
Joined: 26 Apr 2010, 17:36

Re: COMMONDIALOG BOX

Post by sal21 »

HansV wrote:
26 Feb 2022, 15:51
Use something like

Code: Select all

    Dim strFile As String
    With CommonDialog1
        .Filter = "Exp Files (*.exp)|*.exp"
        .InitDir = "C:\MyDir"
        .ShowOpen
        If .FileName = "" Then
            MsgBox "No file selected!"
            Exit Sub
        End If
        strFile = .FileName
    End With
but strFile = .FileName contain dir & filename...
in other var i need only the name of file

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: COMMONDIALOG BOX

Post by HansV »

Then use

Code: Select all

        strFile = Mid(.FileName, InStrRev(.FileName, "\") + 1)
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4346
Joined: 26 Apr 2010, 17:36

Re: COMMONDIALOG BOX

Post by sal21 »

HansV wrote:
26 Feb 2022, 19:01
Then use

Code: Select all

        strFile = Mid(.FileName, InStrRev(.FileName, "\") + 1)
:clapping: