Results 1 to 2 of 2

Thread: OpenFileDialog box malfunctions

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    OpenFileDialog box malfunctions

    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.
    Last edited by hometech; 10-22-2012 at 12:39 PM.

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi hometech,

    Welcome to ExcelFox !!

    arrange the lines this way

    Code:
    fd.InitialFileName = "c:\"
    fd.Title = "Choose Project"
    fd.InitialView = msoFileDialogViewList
    fd.Filters.Clear
    fd.Filters.Add "MS Project Files", "*.mpp"
    fd.FilterIndex = 1
    fd.ButtonName = "Choose this file"
    FileChosen = fd.Show
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Did You Know :: Format Comment Box Using Shapes
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 06-16-2013, 10:50 PM
  2. Linking a table to a text box
    By Safal Shrestha in forum Excel Help
    Replies: 6
    Last Post: 04-25-2013, 10:37 AM
  3. Setting up a check box
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 08-07-2012, 08:26 AM
  4. Message Box Before Saving Document
    By Lucero in forum Excel Help
    Replies: 2
    Last Post: 04-15-2012, 07:09 AM
  5. Linking Cells In a Dropdown Box
    By Kerry78 in forum Excel Help
    Replies: 2
    Last Post: 10-20-2011, 07:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •