Hello, i have this VBA code that opens a file dialog box and allows the user browse/search for a file and select the file that is needed. The issue i'm having with this is is that when i run the macro for the first time, it does not follow all the filter constraints set (i.e show only MS project files, .mpp and also, i set the default folder to be opened to "c:\" but it opens my documents ) but after the first run, the it obeys the filter constraints and works normally, please how do i go about this.
Code:
Private Sub Opener()
Dim fd As FileDialog
Dim FileName As String
Dim part As String
Set fd = Application.FileDialog(msoFileDialogOpen)
Dim FileChosen As Integer
FileChosen = fd.Show
fd.Title = "Choose Project"
fd.InitialFileName = "c:\"
fd.InitialView = msoFileDialogViewList
fd.Filters.Clear
fd.Filters.Add "MS Project Files", "*.mpp"
fd.FilterIndex = 1
fd.ButtonName = "Choose this file"
If FileChosen <> -1 Then
'didn't choose anything (clicked on CANCEL)
MsgBox "No file opened"
Exit Sub
Else
'get file, and open it (NAME property
'includes path, which we need)
part = fd.SelectedItems(1)
'Documents.Open (FileName)
'part = FileName
Set objx = ActiveDocument.InlineShapes.AddOLEObject(ClassType:="MSProject.Project", _
FileName:=part, LinkToFile:=False, DisplayAsIcon:=False, Range:=ActiveDocument.Frames(1).Range)
objx.Height = 300
objx.Width = 480
'Open object ready for typing
Set objx = Nothing
End If
End Sub
i appreciate your suggestions.
Bookmarks