+ Reply to Thread
Results 1 to 5 of 5

Macro to count specific file in folder

  1. #1
    Registered User
    Join Date
    02-22-2013
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    22

    Macro to count specific file in folder

    Hello!

    So, I have been searching all over the internet for the solution to this problem I am having and I am hoping someone here can help me out.

    What my macro supposed to do is to count a number of specific files in a folder then add the count +1 at the end of the file.

    Here is the part of code I have...

    Please Login or Register  to view this content.
    I have tried changing the i definition to integer, changing the variable "*" to "*.pdf", removing criteria and tried to find all files in a folder, but none worked.

    what happens now is macro only goes through 1 file (strFilename2 when should be going through myfile1), then determines that myfile1 ="" so it keeps renewing the file already in the folder with the same name.

    I am really not sure what is wrong here and how it get the second criteria mixed with the first one, and why it is not counting.

    I appreciate all your help.
    Jake

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Macro to count specific file in folder

    I don't understand what you are doing; however,...
    Name Statement

    Renames a disk file, directory, or folder.

    Syntax

    Name oldpathname As newpathname

    The Name statement syntax has these parts:

    Part Description
    oldpathname Required. String expression that specifies the existing file name and location — may include directory or folder, and drive.
    newpathname Required. String expression that specifies the new file name and location — may include directory or folder, and drive. The file name specified by newpathname can't already exist.
    Dim OldName, NewName

    OldName = "OLDFILE"
    NewName = "NEWFILE" ' Define file names.

    Name OldName As NewName ' Rename file.

    OldName = "C:\MYDIR\OLDFILE"
    NewName = "C:\YOURDIR\NEWFILE"
    Name OldName As NewName ' Move and rename file.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    02-22-2013
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Macro to count specific file in folder

    Ben. Van Johnson,

    Thank you for your reply but that is not what I am looking to do; I understand the name statement but I am not renaming anything, and if any, I am trying to avoid overwriting the existing file.

    What I am trying to accomplish is simple; counting files that meet the specific criteria.

    Say you have a lot of document regarding tax. All named "tax" but say you want to put "2", "3", or "ver 2" and so on at the end of the file name. To accomplish this, you need to count the number of files with name starting "tax" in that folder and add the count + 1 at the end to come to file name "tax ver 2.pdf". This is what I am doing, or trying to do.

    To explain my code, first part till the msgbox is checking if the directory exists, and if not, create one.

    Second part till printing to pdf determines the file name based on the msgbox answer; Yes or No. For each answer, file name differs slightly. It worked perfectly till when I had to run the macro more than once a day for a same answer, in which case, need to save both files without overwriting one. "IF" statement sees if the file already exists or not, and if not, it is all good, but if it does, then that is when I start to have a problem.

    By the way, changing "Else" to "Elseif" does not change my result.

    Hope this clearer a little bit better.

    Jake

  4. #4
    Registered User
    Join Date
    02-22-2013
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Macro to count specific file in folder

    Anybody...?

  5. #5
    Registered User
    Join Date
    02-22-2013
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Macro to count specific file in folder

    bumping it up...

+ 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] Need a Macro to group certain columns and save them as a separate file in specific folder
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-31-2013, 11:51 AM
  2. [SOLVED] macro to save file to specific folder with file name from cell reference
    By mezza89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 11:32 AM
  3. [SOLVED] save macro with specific folder and file name and type
    By wolfm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2013, 10:08 AM
  4. Macro for copying specific data from excel files in a folder to a newly created excel file
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2012, 02:24 PM
  5. Macro to count specific cells on predicted excel file
    By fcomino in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-19-2010, 10:47 AM

Tags for this Thread

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