+ Reply to Thread
Results 1 to 11 of 11

VBA Open Specific File Type

Hybrid View

hobbiton73 VBA Open Specific File Type 03-30-2015, 08:11 AM
davesexcel Re: VBA Open Specific File... 03-30-2015, 08:27 AM
hobbiton73 Re: VBA Open Specific File... 03-30-2015, 08:31 AM
davesexcel Re: VBA Open Specific File... 03-30-2015, 09:11 AM
hobbiton73 Re: VBA Open Specific File... 03-31-2015, 01:16 AM
davesexcel Re: VBA Open Specific File... 03-31-2015, 06:38 AM
hobbiton73 Re: VBA Open Specific File... 03-31-2015, 07:13 AM
JosephP Re: VBA Open Specific File... 03-31-2015, 12:49 PM
hobbiton73 Re: VBA Open Specific File... 04-01-2015, 01:51 AM
snb Re: VBA Open Specific File... 04-01-2015, 04:03 AM
JosephP Re: VBA Open Specific File... 04-03-2015, 03:50 AM
  1. #1
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    VBA Open Specific File Type

    Hi, I wonder if someone could help me please.

    Using a source file I found here:http://www.learnexcelmacro.com/wp/20...d-sub-folders/, I've put together the following code which downloads a list of files when the workbook opens.

    Sub btnFetchFiles()
        
        iRow = 14
        fPath = "XXXXXXXXXX"
        Const strPattern As String = "*.dat"
        If fPath <> "" Then
            
            Set FSO = New Scripting.FileSystemObject
            If FSO.FolderExists(fPath) <> False Then
                Set SourceFolder = FSO.GetFolder(fPath & strPattern)
                
                    IsSubFolder = True
                
                    Call ListFilesInFolder(SourceFolder, IsSubFolder)
                    Call ResultSorting(xlAscending, "C14", "D14", "E14")
                    
                    Call ListFilesInFolderXtn(SourceFolder, IsSubFolder)
                    Call ResultSorting(xlAscending, "C14", "D14", "E14")
                
                lblFCount.Caption = iRow - 14
                
            Else
                MsgBox "Selected Path Does Not Exist !!" & vbNewLine & vbNewLine & "Select Correct One and Try Again !!", vbInformation, "File Manager - http://www.LearnExcelMacro.Com"
            End If
        Else
            MsgBox "Folder Path Can not be Empty !!" & vbNewLine & vbNewLine & "", vbInformation, "File Manager - http://www.LearnExcelMacro.Com"
        End If
        
    End Sub
    The problem I have is with this line:
    Set SourceFolder = FSO.GetFolder(fPath & strPattern)
    where I'm trying to list a specific file type, but when I run the code I recieve a 'Path not found' error.

    I know the fPath is correct, but I just wondered whether someone could point out where I've gone wrong on trying to download a specific file type.

    Many thanks and kind regards

    Chris

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: VBA Open Specific File Type

    fPath = "XXXXXXXXXX"
    is not a file path

  3. #3
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Open Specific File Type

    Hi @davesexcel, thank you for taking the time to reply to my post.

    No it isn't but I didn't want to publish the real file path.

    Kind Regards

    Chris

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: VBA Open Specific File Type

    Can you attach a pic of the warning msg?

  5. #5
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Open Specific File Type

    Hi @davesexcel, forgive me but I'm not sure what a picture will show other than the error message. I can say though that debug does highlight this line as the cause:
    Set SourceFolder = FSO.GetFolder(fPath & strPattern)
    .

    Many thanks and kind regards

    Chris
    Last edited by hobbiton73; 03-31-2015 at 01:55 AM.

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: VBA Open Specific File Type

    Show the darn file path, or a fake file path, who cares, I want to see how the file path looks.

  7. #7
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Open Specific File Type

    Hi @davesexcel, please find a file path as you asked for.

    fPath = "\\c\s\xxx\xxxxxx\xxxxxx\Dragon - Application-Specific Script Conversion 2014\Converted Scripts\Done\"

    Kind Regards

    Chris

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Open Specific File Type

    getfolder gets a reference to a folder not a file-it oughta be
    Set SourceFolder = FSO.GetFolder(fPath)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  9. #9
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Open Specific File Type

    Hi @JospehP, thank you for taking the time to reply to my post.

    Thank you for the giuidance, but can you tell me please how I fetch a specific file type then.

    Many thanks and kind regards

    Chris

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: VBA Open Specific File Type

    Sub M_snb()
       msgbox createobject(wscript.shell").exec("cmd /c Dir ""G:\OF\*.dat"" /b").stdout.readall
    End Sub
    you can sort by name, by size , by time using the /o switch



  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Open Specific File Type

    Chris
    you oughta change the ListFilesInFolder routine so it checks the extension on the name of each file

+ 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. Use Macro to open a file with excel (underfined type of file)
    By tatfish87 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-21-2014, 09:38 PM
  2. [SOLVED] Open specific folder, select file to open and copy then paste
    By Kranky in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-22-2012, 12:14 AM
  3. [SOLVED] Default file type to open in 2003
    By Circe in forum Excel General
    Replies: 2
    Last Post: 02-10-2006, 03:00 PM
  4. How to select a specific file type
    By MervB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2005, 04:10 AM
  5. Replies: 4
    Last Post: 02-18-2005, 10:06 PM

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