+ Reply to Thread
Results 1 to 5 of 5

How to capture file name in a folder?

  1. #1
    Gregg
    Guest

    How to capture file name in a folder?

    In a folder exists one .ppt file and a non .ppt file. In vba I want to
    capture the name of the ppt file. Can someone tell me the best way to
    do that?

    For example, the path is c:\whatever and the ppt name might be
    anything. I just want the name of the ppt file, not the other file.

    Thanks.


  2. #2
    Jim Cone
    Guest

    Re: How to capture file name in a folder?

    Gregg,

    Sub FindFile()
    Dim strPath As String
    Dim strFile As String
    strPath = "C:\whatever\*.ppt"
    strFile = Dir(strPath)
    MsgBox strFile
    End Sub

    Jim Cone
    San Francisco, USA

    "Gregg" <[email protected]> wrote in message
    news:[email protected]...
    In a folder exists one .ppt file and a non .ppt file. In vba I want to
    capture the name of the ppt file. Can someone tell me the best way to
    do that?

    For example, the path is c:\whatever and the ppt name might be
    anything. I just want the name of the ppt file, not the other file.

    Thanks.


  3. #3
    Roy Harrill
    Guest

    Re: How to capture file name in a folder?

    Try this --

    Sub GetPPT()

    Dim f as string
    f = Dir("C:\whatever\*.ppt")

    End Sub


    "Gregg" <[email protected]> wrote in message
    news:[email protected]...
    > In a folder exists one .ppt file and a non .ppt file. In vba I want to
    > capture the name of the ppt file. Can someone tell me the best way to
    > do that?
    >
    > For example, the path is c:\whatever and the ppt name might be
    > anything. I just want the name of the ppt file, not the other file.
    >
    > Thanks.
    >




  4. #4
    Gregg
    Guest

    Re: How to capture file name in a folder?

    Thanks, Jim. I did keep trying and had come up with the following, but
    I like yours much better. Thanks.

    Dim sFileNm As String
    With Application.FileSearch
    .NewSearch
    .LookIn = "c:\whatever"
    .SearchSubFolders = False
    .FileName = "*.ppt"
    .Execute
    sFileNm = Right(.FoundFiles(1), _
    (Len(.FoundFiles(1)) - _
    InStrRev(.FoundFiles(1), "\")))
    End With

    Jim Cone wrote:
    > Gregg,
    >
    > Sub FindFile()
    > Dim strPath As String
    > Dim strFile As String
    > strPath = "C:\whatever\*.ppt"
    > strFile = Dir(strPath)
    > MsgBox strFile
    > End Sub
    >
    > Jim Cone
    > San Francisco, USA
    >
    > "Gregg" <[email protected]> wrote in message
    > news:[email protected]...
    > In a folder exists one .ppt file and a non .ppt file. In vba I want to
    > capture the name of the ppt file. Can someone tell me the best way to
    > do that?
    >
    > For example, the path is c:\whatever and the ppt name might be
    > anything. I just want the name of the ppt file, not the other file.
    >
    > Thanks.



  5. #5
    Gregg
    Guest

    Re: How to capture file name in a folder?

    Thanks, Roy. I went back and read about the DIR function. Nice.

    Roy Harrill wrote:
    > Try this --
    >
    > Sub GetPPT()
    >
    > Dim f as string
    > f = Dir("C:\whatever\*.ppt")
    >
    > End Sub
    >
    >
    > "Gregg" <[email protected]> wrote in message
    > news:[email protected]...
    > > In a folder exists one .ppt file and a non .ppt file. In vba I want to
    > > capture the name of the ppt file. Can someone tell me the best way to
    > > do that?
    > >
    > > For example, the path is c:\whatever and the ppt name might be
    > > anything. I just want the name of the ppt file, not the other file.
    > >
    > > Thanks.
    > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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