Could this be better?????

Chris84

Board Regular
Joined
Aug 17, 2012
Messages
78
Hi

I have spent a big part of the day fighting a losing battle, but have a work around. What I need to do is update links in several different files which are password protected to open and modify.

The file will be used by different people so getting them to input the password's is not a option.

I have put some simple code together which opens the protected workbook then reapplies the links for the file and closes the workbook which works but is a lot slower than before the passwords was used.

Is there a smarter way of doing this?

Code:
Sub OpenUpdate()
Dim TestFile As String
TestFile = "C:\TestPWord.xlsm"
Workbooks.Open Filename:=TestFile, _
    Password:="Luck", ReadOnly:=True
ThisWorkbook.ChangeLink Name:=TestFile, NewName:= _
    TestFile, Type:=xlExcelLinks
Workbooks("TestPword.xlsm").Close savechanges:=False
End Sub


Any feedback greatly appreciated
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi Chris,

When your code opens the linked workbook, the values in the calling workbook referencing that linked workbook should be updated automatically, so you could remove the line:
Code:
ThisWorkbook.ChangeLink Name:=TestFile, NewName:=  TestFile, Type:=xlExcelLinks

Also, your update might run quicker if you turn off calculation and screenupdating during the process.

Code:
Sub OpenUpdate()
    Dim TestFile As String
    TestFile = "C:\TestPWord.xlsm"

    On Error GoTo CleanUp
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Workbooks.Open Filename:=TestFile, Password:="Luck", ReadOnly:=True
    ActiveWorkbook.Close savechanges:=False

CleanUp:
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub

I had thought the values might not update with Calculation set to Manual, but in a test, they get updated regardless.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,489
Messages
6,055,724
Members
444,814
Latest member
AutomateDifficulty

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top