+ Reply to Thread
Results 1 to 5 of 5

Select file pop up not flawless

Hybrid View

rpinxt Select file pop up not... 04-30-2014, 10:39 AM
nathansav Re: Select file pop up not... 04-30-2014, 10:41 AM
rpinxt Re: Select file pop up not... 04-30-2014, 10:47 AM
nathansav Re: Select file pop up not... 04-30-2014, 10:49 AM
rpinxt Re: Select file pop up not... 04-30-2014, 10:53 AM
  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Select file pop up not flawless

    Hi Guys,
    Can you please look at this code:
    Sub SelectWorkFiles()
        Dim FileName As Variant
        Dim Filt As String, Title As String
        Dim FilterIndex As Integer, Response As Integer
        
        '   Set to Specified Path\Folder
            ChDir "P:\Finance\2014\Month closing\0.1 Macro files\B1 - Inventory Movement\Work Files\"
        '   Set File Filter
            Filt = "Excel Files (*.xls*), *.xls*"
        '   Set *.* to Default
            FilterIndex = 5
        '   Set Dialogue Box Caption
            Title = "Please choose your desired file."
        '   Get FileName
            FileName = Application.GetOpenFilename(FileFilter:=Filt, _
                FilterIndex:=FilterIndex, Title:=Title, MultiSelect:=False)
        '   Exit if Dialogue box cancelled
            If FileName = False Then
                Response = MsgBox("No File was selected", vbOKOnly & vbCritical, "Selection Error")
                Exit Sub
            End If
    
            Workbooks.Open FileName
    End Sub
    It does not always work....
    Although the Drive is specified it still won't open directly into the correct folder.
    But if I then select drive P: then exit the selection box, and run the macro again it does open directly to the correct folder.
    And for all instances after also.

    However when I close the workbook and open it another day again the first time it does not open directly in the correct spot.
    This way this macro is not very useful.
    Can anybody see where it could go wrong?
    Thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Select file pop up not flawless

    Is P a mapped drive? Try using the actual path, not the mapped drive letter.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: Select file pop up not flawless

    What do you mean with a mapped drive?
    P: is our main drive we do all work on, then we have our personal drive H: and ofcourse you got C: drive.
    All these drives are mapped, so in my explorer visible.

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Select file pop up not flawless

    Yes, sometimes the UNC path has to be passed. It also stops errors with people who have mapped to Q, in windows explorer look at what P refers to and replace P: in your code with that path.

  5. #5
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: Select file pop up not flawless

    Well I think you pointed me in the right direction.
    I added ChDrive "P" to the code as apparently the ChDir does not automatically change drive numbers.

    Like this it appears to work
    Sub SelectWorkFiles()
        Dim FileName As Variant
        Dim Filt As String, Title As String
        Dim FilterIndex As Integer, Response As Integer
        
        '   Set to Specified Path\Folder
            ChDrive "P"        
            ChDir "P:\Finance\2014\Month closing\0.1 Macro files\B1 - Inventory Movement\Work Files\"
        '   Set File Filter
            Filt = "Excel Files (*.xls*), *.xls*"
        '   Set *.* to Default
            FilterIndex = 5
        '   Set Dialogue Box Caption
            Title = "Please choose your desired file."
        '   Get FileName
            FileName = Application.GetOpenFilename(FileFilter:=Filt, _
                FilterIndex:=FilterIndex, Title:=Title, MultiSelect:=False)
        '   Exit if Dialogue box cancelled
            If FileName = False Then
                Response = MsgBox("No File was selected", vbOKOnly & vbCritical, "Selection Error")
                Exit Sub
            End If
    
            Workbooks.Open FileName
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Modify existing code to select file instead of select folder
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2014, 09:41 AM
  2. Replies: 7
    Last Post: 10-30-2012, 07:14 AM
  3. Replies: 2
    Last Post: 07-20-2012, 09:38 AM
  4. Macro - select external file and range within that file
    By D_N_L in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-25-2011, 02:18 PM
  5. Update Querytable linked to CSV file without having to select the file manually
    By KRAND in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2011, 09:24 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1