+ Reply to Thread
Results 1 to 6 of 6

Macro to auto update links to password protected workbooks

Hybrid View

  1. #1
    Registered User
    Join Date
    04-21-2016
    Location
    Minneapolis, Minnesota
    MS-Off Ver
    2016
    Posts
    26

    Macro to auto update links to password protected workbooks

    I am new to VBA.

    I have a master workbook that pulls summary data from several workers' workbooks.

    The worker's workbooks are all password protected with unique passwords.

    Is there a macro that will let me update links and then enter the passwords to each of the worker's workbooks?

    Record macro produced nothing but the name and description.

    I tried to use some of the codefrom the last post on this thread http://www.excelforum.com/excel-prog...ugh-vba-2.html but I am getting a runtime error.

    Thanks,
    Mark
    Last edited by armlegx; 04-21-2016 at 03:39 PM. Reason: update

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Macro to auto update links to password protected workbooks

    Welcome to the forum

    This is a format that will open a file so that you can modify it

    Workbooks.Open Filename:="D:\Documents\ABC\File001.xlsx", ReadOnly:=False, Password:="OpenTheDoor"
    Are all the files in a single folder?
    Are there any other files in that folder?
    Where are the passwords associated with each file held?
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  3. #3
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: Macro to auto update links to password protected workbooks

    Hi Mark,

    Depending on how the workbooks are protected, here are a couple of examples.

    If the workbook is password protected for opening (Password) and for modification (WriteResPassword) and you want full access rights, then this would be the code in VBA to open it. If it is only password protected for opening or only password protected for modifying and you need full access rights, then you would use whichever one is in effect.
    Workbooks.Open Filename:="C:\Filename.xls", Password:="Admin", WriteResPassword:="Admin"
    If the workbook is password protected for opening and you only need readonly rights to extract data, you could use this code.
    Workbooks.Open Filename:="C:\Filename.xls", ReadOnly:=True, Password:="Admin"
    Based on your post, it sounds like you only need to open the workbooks to extract information, so it sounds like the 2nd option would be what you want.

    Hope that helps,

    Dan
    Last edited by djbomaha; 04-22-2016 at 05:05 AM. Reason: Modified paragraph structure

  4. #4
    Registered User
    Join Date
    04-21-2016
    Location
    Minneapolis, Minnesota
    MS-Off Ver
    2016
    Posts
    26

    Re: Macro to auto update links to password protected workbooks

    The files are all in the same directory.
    I created a new workbook called "List.xlsX" that contains the path and passwords.

    So this is the macro that I am working with.
    I am able to have the macro open all of the password protected files.
    The current issue I am having is I can get the macro to either not close any of the workbooks when it is done, or it will close all of the workbooks, except for the "list" workbook with the passwords.

    In an ideal world, I could move the list workbook to a sheet in my summary workbook, but I can't figure out how to have the macro refer to that sheet specifically. If I was able to do that, the Workbooks(i).Close SaveChanges:=False would, I think close all of the daughter books. Currently, it closes everything but "list".

    HTML Code: 
    You can see all of the attempts I have made to get this to work commented out.
    Am I on the right track at all?

    Thanks again,
    Mark

  5. #5
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: Macro to auto update links to password protected workbooks

    Hi Mark,

    Here is your code modified so it gets the workbook names and passwords from the List.xlsx file and then opens and closes each password protected workbook. Instead of keeping the "List.xlsx" file open and reading from it while opening each workbook, the code below opens "List.xlsx", populates arrays for the workbook names and passwords, closes "List.xlsx" and then runs through another loop to deal with the password protected workbooks.

    
    Sub updateme()
    
        Dim myFileNames() As String
        Dim myPasswords() As String
        Dim myRealWkbkName As String
        Dim LastRowA1 As Long
        Dim LastRowB1 As Long
        Dim PWWorkbook As Workbook
        Dim SourceWorkbook As Workbook
        Dim WorkbookPath As String
        Dim i As Integer
        Dim LastRow As Long
        Dim LastColumn As Long
        Dim rng As Range
        
        ' Turn OFF events
        Application.ScreenUpdating = False
        
        WorkbookPath = "C:\!!!!Users\wfh309\Desktop\New Log Setup\January 2016\Case Review Logs\"
        myRealWkbkName = WorkbookPath & "List.xlsx"
       
        ' Open List.xlsx and retrieve reference workbook names and passwords
        Workbooks.Open myRealWkbkName, UpdateLinks:=False
        Set PWWorkbook = ActiveWorkbook
        
        ' Verify list of workbook names is same length as list of corresponding passwords
        LastRowA1 = PWWorkbook.Sheets("List").[A1].End(xlDown).Row
        LastRowB1 = PWWorkbook.Sheets("List").[B1].End(xlDown).Row
        
         If LastRowA1 <> LastRowB1 Then
            MsgBox "check names & passwords--qty mismatch!"
            Exit Sub
         End If
        
        ' Populate wkbName() and wkbPass() arrays from List.xlsx
        ReDim myFileNames(1 To LastRowA1) As String
        ReDim myPasswords(1 To LastRowA1) As String
        For i = 1 To LastRowA1
            myFileNames(i) = PWWorkbook.Sheets(1).Cells(i, 1).Value
            myPasswords(i) = PWWorkbook.Sheets(1).Cells(i, 2).Value
        Next i
        PWWorkbook.Close False
            
        ' Open Password Protected Workbooks, Execute code and close workbook
        For i = 1 To LastRowA1
            Workbooks.Open WorkbookPath & myFileNames(i), UpdateLinks:=False, Password:=myPasswords(i)
            ' < CODE HERE >
            Workbooks(myFileNames(i)).Close SaveChanges:=False
        Next i
    
        ' Turn ON events
        Application.ScreenUpdating = True
        
    End Sub
    Hope that helps,

    Dan

  6. #6
    Registered User
    Join Date
    04-21-2016
    Location
    Minneapolis, Minnesota
    MS-Off Ver
    2016
    Posts
    26

    Re: Macro to auto update links to password protected workbooks

    This is exactly what I needed.
    Its working in my test folder. I will try it on the network tomorrow. The only difference should be redefining the path.
    Thanks so much. Yesterday, I bought a book on VBA so hopefully I can figure this out on my own next time.

    Best,
    Mark
    Last edited by armlegx; 04-24-2016 at 04:02 PM.

+ 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. Maintain links between password protected workbooks
    By AHuntDIA in forum Excel General
    Replies: 0
    Last Post: 04-24-2014, 01:08 PM
  2. Record a macro to update links to password protected workbooks
    By smithc1970 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2014, 08:05 AM
  3. Code to update links when the source workbooks are password protected
    By jobdillon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2014, 01:02 PM
  4. Macro to update links when the source workbooks are password protected
    By srawal in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-12-2012, 07:55 AM
  5. Updating Links from Password protected Workbooks
    By rhysaubs in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-06-2010, 10:24 AM
  6. Replies: 0
    Last Post: 04-06-2009, 09:42 PM
  7. Links to password protected workbooks
    By Nesta777 in forum Excel General
    Replies: 1
    Last Post: 07-19-2006, 07:40 AM

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