Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2007, 07:04 PM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default FileSearch Extension Problems

Good Day:

I am trying to use the following code to retrieve filenames from a drive and post them in excel. It works admirably, but I'm having two problems.

1)I need the file extensions to be listed as well for the server I'll upload to later.

    ex.) examplefile.pdf not just examplefile

2)I need to prevent certain file types from being added (same reason).

    ex.) examplefile.doc

3)Any uppercase file extensions must be converted to lowercase

    ex.) examplefile.PDF --> examplefile.pdf

4)Special characters in the File Name (!,@,#,$,% etc.) must be replaced be underscore.

That said, here's the code:

Sub GetFiles()
    Dim ary
    Set pa = Application.FileSearch
    With pa
        .LookIn = "X:\"
        .SearchSubFolders = False
        .Filename = "*.*"

        If .Execute(SortBy:=msoSortByFileName) > 0 Then

            For i = 1 To .FoundFiles.Count
                ary = Split(.FoundFiles(i), "\")
                Range("A500").End(xlUp).Offset(1, 0).Value = _
                Left(ary(UBound(ary)), _
                InStr(ary(UBound(ary)), ".") - 1)
            Next i

        End If

    End With
End Sub

I've tried using the name function, among other things, but it doesn't work with wildcards. I apologize in advance if the answer to this question is obvious.

Thanks in advance,

John Smith.

-John Smith





Similar Threads
Thread Thread Starter Forum Replies Last Post
xml extension Maxxim BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 October 27th, 2007 04:23 AM
Set fs = application.filesearch yismen Excel VBA 0 May 25th, 2007 02:18 PM
FileSearch method fails maxpotters Excel VBA 6 February 23rd, 2005 05:19 PM
What file extension should I use? pigtail Javascript 3 April 12th, 2004 02:58 PM
Server Extension using C++ Margaret Wright C++ Programming 2 December 17th, 2003 06:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.