|
-
Apr 16th, 2005, 01:24 PM
#1
Thread Starter
Addicted Member
Excel - Link to protected file
I have hundred of files to which I want to link specific cells in one sheet.
The thing is, all of those file are password protected.
Now obviously when I open my sheet, I get hundreds of prompt for passwords.
Fortunately, the password is the same for all the sheets.
Is there a way I supply by code or else the requested password?
Does anyone have a suggestion on how I should go about this?
TIA
Dniss
-
Apr 16th, 2005, 01:43 PM
#2
Re: Excel - Link to protected file
Yes, you can pass the password to the Workbook during an Unprotect method call.
If this is from VB6 that you are automating this then...
VB Code:
Option Explicit
'Add a reference to MS Excel xx.0 Object Linrary
Private Sub Command1_Click()
Dim oApp As Excel.Application
Dim oWB As Excel.Workbook
Set oApp = New Excel.Application
oApp.Visible = True
Set oWB = oApp.Workbooks.Open("C:\Book1.xls")
oWB.Unprotect "Password"
'Do your stuff
'...
'...
oWB.Close True 'Save changes
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing
End Sub
Now if your Sheet is all that has the protection then you can do something similar but for the Sheet object.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 16th, 2005, 01:50 PM
#3
Thread Starter
Addicted Member
Re: Excel - Link to protected file
Hi there Rob, thanks for your quick reply.
I did see your answer to the other post. You code appears to be
opening the source file and supplying the pw, which is not what
I'm doing.
I don't want to open the source file, I want to update links in one file
that are referring to passworded files without having to type in each
time the password.
I hope this is more explicit.
TIA
-
Apr 16th, 2005, 02:00 PM
#4
Re: Excel - Link to protected file
But the other linked files are not open correct?
Then its the formula that contains the references to the other workbook/sheets.
Sorry for the confusion, but I got a headache this morning
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 16th, 2005, 02:07 PM
#5
Thread Starter
Addicted Member
Re: Excel - Link to protected file
Correct, none of the source files are openned.
I guess I was looking into some trigger event for the "update link"
that would allow me to supply the password by code.
Now I guess I'll have to look into some kind of ADO connection.
Thanks for trying nevertheless.
-
Apr 16th, 2005, 02:18 PM
#6
Thread Starter
Addicted Member
Re: Excel - Link to protected file
Can't do it with ADO either. Darn that's a tough one.
-
Apr 16th, 2005, 03:08 PM
#7
Addicted Member
Re: Excel - Link to protected file
i think that the linked files 'are' actually opened, but background processed.
so, taking this into account, if you open the file, and do not update links, then use robdoggs code to open each sheet with password, but background process them.
e.g.
VB Code:
Application.ScreenUpdating = false
maybe that would work?
if you fail to plan, you plan to fail
-
Apr 16th, 2005, 05:22 PM
#8
Thread Starter
Addicted Member
Re: Excel - Link to protected file
Yes I understood what he meant.
I believe this is the only way to go, aside from removing all pw.
I thought there could perhaps be some kind of custom event that
could intercept the pw request. Even the workbook_activate event
comes after...
And humm I'm not sure about the sheet actually being opened in
the backgroud, perhaps you're right but I have my doubts.
Thanks all the same.
-
Apr 18th, 2005, 01:44 AM
#9
Thread Starter
Addicted Member
Re: Excel - Link to protected file
I guess I did not fully understand the implications. I thought I could perhaps create some kind of custom event. Thanx Rob you were right, it appears to be the only way to do it.
This help me alot also:
http://support.microsoft.com/?kbid=214314
What I ended up doing is using a sheet where I list all filename in col A, and it's filepath in col B.
I created an input box for the user to enter the pw once (triggered by Workbook_Open event) and proceed to load all the files, reading col A:B for name and path.
Here's my main routine:
========================
Option Explicit
Function UpdateLink(Pw As String)
On Error GoTo Err_UpdateLink
Dim Cell As Range
Dim i As Integer
Dim oldStatusBar As Boolean
PWForm.Hide
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
oldStatusBar = Application.DisplayStatusBar
Application.StatusBar = "Updating links..."
i = 0
With Sheets("FileList")
Set Cell = .Range("A2")
Do While Cell.Offset(i, 0).Value <> ""
Workbooks.Open Filename:=Cell.Offset(i, 1) & "\" & Cell.Offset(i, 0), UpdateLinks:=3, ReadOnly:=True, Password:=Pw
Application.StatusBar = "Updating link..." & Cell.Offset(i, 0)
Workbooks(Cell.Offset(i, 0).Value).Close
i = i + 1
Loop
End With
Exit_Err_UpdateLink:
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
Application.ScreenUpdating = True
Exit Function
Err_1004:
MsgBox "Wrong password, links not updated"
Resume Exit_Err_UpdateLink
Err_UpdateLink:
If Err.Number = 1004 Then GoTo Err_1004
MsgBox "Error finding file " & Cell.Offset(i, 0)
Resume Exit_Err_UpdateLink
End Function
========================================
Comments and suggestions are welcome!
Thanks
Last edited by D-niss; Apr 18th, 2005 at 04:00 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|