+ Reply to Thread
Results 1 to 7 of 7

Open all files in a folder using list of password

  1. #1
    Registered User
    Join Date
    06-11-2021
    Location
    Vietnam
    MS-Off Ver
    MS Office 365 Pro
    Posts
    5

    Open all files in a folder using list of password

    Dear all,

    I am a beginner in using macro excel for automation.

    I have nearly 100 of excel files with password. I would like to do as follows.

    - Step 1: I will choose Input folder contains all excel files.
    - Step 2: I will choose Output folder contains all output excel file.
    - Step 3: File structure and password are as follows.

    File structure Password
    PV*.xlsx PV
    JP*.xls JP
    PIT calculation*01-20*.xlsx 0120
    PIT calculation*02-20*.xlsx 0220
    PIT calculation*03-20*.xlsx 0320
    PIT calculation*04-20*.xlsx 0420
    PIT calculation*05-20*.xlsx 0520
    PIT calculation*06-20*.xlsx 0620
    PIT calculation*07-20*.xlsx 0720
    PIT calculation*08-20*.xlsx 0820
    PIT calculation*09-20*.xlsx 0920
    PIT calculation*10-20*.xlsx 1020
    PIT calculation*11-20*.xlsx 1120
    PIT calculation*12-20*.xlsx 1220

    Step 4: if the input file in .xls, convert it to .xlsx

    I have write a code as follows but when I run it, it seems endless run. Please help to correct my code. Thank you.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by smiledt06; 06-17-2021 at 11:14 AM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Open all files in a folder using list of password


    Hi,

    according to your attachment, only 2 files from the Input folder are matching your 'File structure' list

    but if for you it's not correct so I first need to know which file(s) must not be treated …

  3. #3
    Registered User
    Join Date
    06-11-2021
    Location
    Vietnam
    MS-Off Ver
    MS Office 365 Pro
    Posts
    5

    Re: Open all files in a folder using list of password

    Quote Originally Posted by Marc L View Post

    Hi,

    according to your attachment, only 2 files from the Input folder are matching your 'File structure' list

    but if for you it's not correct so I first need to know which file(s) must not be treated …
    Dear Marc,

    Sorry for the confusing.

    So, what I want is:
    - PV SV_2020(10) 薪水.xlsx and 4.PV V_2020(2) 薪水.xlsx: these files must be open with password "PV" then save as new file without password.
    - 5.JP Salary -Mar 2020(pw).xls; 4.JP Salary -Feb 2020(pw).xls; JP Salary Nov 2020(pw).xls : these files must be open with password "JP" then save as xlsx without password.
    - PIT calculation 11-20.xlsx: must be open with password "1120" then save as new file without password.
    - PIT calculation 12-20 .xlsx: must be open with password "1220" then save as new file without password.

    Your help is highly appreciated.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    • As yet stated according to your 'File structure' list only 2 files can be treated so you must first correct this list

    • On my side the Dir VBA function can not work 'cause of the asian characters in some files names so according to your attachment :

    PHP Code: 
    Sub Demo1()
            
    Dim PF$, oF As ObjectV
        With Sheet1
                P 
    = .[TRANSPOSE(B2:B3&IF(RIGHT(B2:B3,1)<>"\","\",""))]
            With .Range("
    A8", .[B7].End(xlDown)).Columns
                F = "
    TRANSPOSE(IF(ISNUMBER(MATCH(" & .Item(1).Address(, , , True) & ",{""#""},0))," & .Item(2).Address(, , , True) & "))"
            
    End With
        End With
        With CreateObject
    ("Scripting.FileSystemObject")
            If .
    FolderExists(P(1)) And .FolderExists(P(2)) Then
                    Application
    .DisplayAlerts False:  Application.ScreenUpdating False
                
    For Each oF In .GetFolder(P(1)).Files
                        V 
    Filter(Evaluate(Replace(F"#"oF.Name)), FalseFalse)
                    If 
    UBound(V) = 0 Then
                        With Workbooks
    .Open(oF.Path, , , , V(0))
                            .
    SaveAs P(2) & Left(oF.NameInStrRev(oF.Name".")) & "xlsx"51, Empty
                            .
    Close
                        End With
                    End 
    If
                
    Next
                    Application
    .DisplayAlerts True:  Application.ScreenUpdating True
            
    Else
                
    Beep
            End 
    If
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 06-13-2021 at 06:57 AM. Reason: tiny optimization …

  5. #5
    Registered User
    Join Date
    06-11-2021
    Location
    Vietnam
    MS-Off Ver
    MS Office 365 Pro
    Posts
    5

    Re: Open all files in a folder using list of password

    Dear Marc L,

    I have updated the file name structure with your code as attached in the macro file but the code only works for the file name PV*.xlsx (password PV) and file name JP*.xls (password JP). The code does not work with the remaining files as follow. Please help me. Thank you.

    PIT calculation 01-20*.xlsx password 0120
    PIT calculation 02-20*.xlsx password 0220
    PIT calculation*03-20*.xlsx password 0320
    PIT calculation*04-20*.xlsx password 0420
    PIT calculation*05-20*.xlsx password 0520
    PIT calculation*06-20*.xlsx password 0620
    PIT calculation*07-20*.xlsx password 0720
    PIT calculation*08-20*.xlsx password 0820
    PIT calculation*09-20*.xlsx password 0920
    PIT calculation*10-20*.xlsx password 1020
    PIT calculation*11-20*.xlsx password 1120
    PIT calculation*12-20*.xlsx password 1220
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Open all files in a folder using list of password


    Thanks for the rep' !

    So the file name structure is still bad as a ".xlsx" file can not be a ".xlsx " file !

    Again, just correct the list and no need to review the code as it well works on my side once the list is correct,
    the reason why of my warning about this list …
    Last edited by Marc L; 06-17-2021 at 02:57 PM.

  7. #7
    Registered User
    Join Date
    06-11-2021
    Location
    Vietnam
    MS-Off Ver
    MS Office 365 Pro
    Posts
    5

    Re: Open all files in a folder using list of password

    My bad. Thank you so much for your help.

+ 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. VBA to open the list of excel files and save with password
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2020, 02:38 AM
  2. [SOLVED] Macro to list and open .xlsm files in folder and sub-folder
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-24-2019, 07:35 PM
  3. [SOLVED] open list of all .csv files in a folder and copy few colums in a excel of same sheet.
    By gnrao80 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-04-2014, 01:19 AM
  4. [SOLVED] Open password protected files in folder using list of passwords
    By Shift-4 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-22-2013, 06:08 PM
  5. [SOLVED] Password array to open all password protected workbook in a folder
    By rename in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-07-2012, 05:06 AM
  6. [SOLVED] Open all files in a SharePoint folder (Problem: Files open out of order)
    By holmstarrunner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2012, 10:13 AM
  7. Replies: 2
    Last Post: 04-15-2005, 12:06 PM

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