Open a file in msofiledialog and show as selected?

Maazter

Registered User.
Local time
Today, 02:36
Joined
Nov 25, 2014
Messages
28
Hi again,

I have another issue that I cannot seem to find the answer to, maybe it's because I do not know how to phrase it correctly :banghead:.

I will try and explain it here..

What I want to do is... open a file dialog from VBA "This of cause is no problem"
the file dialog is opened from a double click function of a textbox holding a link to a picture, what i want to happen is... when the explorer opens I want it to show only the picture that was linked in the textbox.

Example "C:\mark\Photos\Picture 085.jpg"

the code i have so far is as follows...

Code:
Private Sub FilePathLbl_DblClick(Cancel As Integer)

    Dim fFile As String
    Dim fd As Office.FileDialog
    Dim retVal As Variant
                        
    Set fd = Application.FileDialog(MsoFileDialogType.msoFileDialogFilePicker)

    
    With fd
    
      

      fd.AllowMultiSelect = False
      fd.InitialFileName = Forms!Addpics!FilePathLbl

      fd.Filters.Clear
      fd.Filters.Add "Pictures", "*.jpg",1
      
        If .Show = True Then
        
           
           fFile = fd.InitialFileName
           retVal.Select = shell("explorer.exe " & fFile)

            
            
        Else
        
            Exit Sub
            
        End If
        
    End With
    
    Set fd = Nothing

End Sub

it opens in the correct folder but it shows all the pictures in that folder.

Thank you in advance of any answer.
 
There is "common dialog" code which should give you what you want.
 
FolowLink should open the picture using the default application for it.
There was a simillar discussion few days ago.
 
Hi guys,

Thank you for your replies, both of which were good but I had tried those.

I have a solution which based on a variable shows the file as selected, here is the code in case anyone else has a similar issue.

Code:
Public Function ImageDblClickFunction(Ctrl As Control)


    Dim Strg As String
    Dim retVal As Variant
    Dim shellparm
 
 Strg = Ctrl.Picture

 
retVal = Dir(Strg)
If retVal <> "" Then

    shellparm = "/select," & Strg
    shell "explorer """"" & shellparm & """""", vbNormalFocus
    
    
End If


End Function
 

Users who are viewing this thread

Back
Top Bottom