Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming,microsoft.public.excel.setup,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 30
Default Opening Protected EXCEL worksheets to update linked data

I have the following code that should open all EXCEL workbooks in a
specified path, and unprotoect any password-protected worksheets to allow
for Link Updates, then close the workbook after password protecting it. For
some reason, I can't get this code to work -- any ideas?
================================
I put the following code in a general module of a sheet1 of a workbook

sub UpdateAllLinks()
Dim vLinkSources
Dim iLinkSource As Integer
Dim AnySheet As Worksheet
sPath = " C:\Documents and Settings\Shane\My Documents\Harcourt
Assessments\password"
sName = Dir(sPath & "*.xls")
do while sName < ""
set bk = Workbook.Open(sPath & sName)
For Each AnySheet In ActiveWorkbook.Worksheets
ActiveWorkbook.Worksheets(AnySheet.Name) _
.Unprotect Password:="mypassword"
Next
vLinkSources = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(vLinkSources) Then
For iLinkSource = LBound(vLinkSources) To UBound(vLinkSources)
ActiveWorkbook.UpdateLink _
vLinkSources(iLinkSource), xlExcelLinks
Next
End If
For Each AnySheet In ActiveWorkbook.Worksheets
ActiveWorkbook.Worksheets(AnySheet.Name) _
.Protect Password:="mypassword"
Next
bk.Close Savechanges:=True
sName = Dir()
Loop
End Sub

Then I put a command button on worksheet1 in that workbook, and added the
following code.

Private Sub CommandButton1_click()
UpdateAllLinks
End sub


Thanks in advance for any assistance


  #2   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming,microsoft.public.excel.setup,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Opening Protected EXCEL worksheets to update linked data

I'm not sure why you need code to unprotect any of the worksheets.

And you can specify that links should be updated when you open the file:

Set bk = Workbooks.Open(Filename:=sPath & sName, UpdateLinks:=1)

Calculations will still update when the worksheet is protected.



doctorjones_md wrote:

I have the following code that should open all EXCEL workbooks in a
specified path, and unprotoect any password-protected worksheets to allow
for Link Updates, then close the workbook after password protecting it. For
some reason, I can't get this code to work -- any ideas?
================================
I put the following code in a general module of a sheet1 of a workbook

sub UpdateAllLinks()
Dim vLinkSources
Dim iLinkSource As Integer
Dim AnySheet As Worksheet
sPath = " C:\Documents and Settings\Shane\My Documents\Harcourt
Assessments\password"
sName = Dir(sPath & "*.xls")
do while sName < ""
set bk = Workbook.Open(sPath & sName)
For Each AnySheet In ActiveWorkbook.Worksheets
ActiveWorkbook.Worksheets(AnySheet.Name) _
.Unprotect Password:="mypassword"
Next
vLinkSources = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(vLinkSources) Then
For iLinkSource = LBound(vLinkSources) To UBound(vLinkSources)
ActiveWorkbook.UpdateLink _
vLinkSources(iLinkSource), xlExcelLinks
Next
End If
For Each AnySheet In ActiveWorkbook.Worksheets
ActiveWorkbook.Worksheets(AnySheet.Name) _
.Protect Password:="mypassword"
Next
bk.Close Savechanges:=True
sName = Dir()
Loop
End Sub

Then I put a command button on worksheet1 in that workbook, and added the
following code.

Private Sub CommandButton1_click()
UpdateAllLinks
End sub

Thanks in advance for any assistance


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming,microsoft.public.excel.setup,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 473
Default Opening Protected EXCEL worksheets to update linked data

The reason may well be that there is no \ at the end of

sPath = " C:\Documents and Settings\Shane\My Documents\Harcourt
Assessments\password"

so you are looking for files called password*.xls in the Harcourt
Assessments folder.

If that is not the problem, it would be helpful if you told us in what
way it failed to work - any messages, any sign of it opening any files
etc.

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - respond to newsgroup

  #4   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming,microsoft.public.excel.setup,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 30
Default Opening Protected EXCEL worksheets to update linked data

Bill -- thank you for your reply ...

I was thinking that the path might have been too long, so I shortened it a
bit, and added the "\" at the end of the path. When I run the macro, I get
the following Error Message:

Run-Time error 424
Object Required

and when I debug the code, it flags this line:

set bk = Workbook.Open(sPath & sName)

Here's my code:

I inserted a Module (Module1) and inserted the following code:
========================
Sub UpdateAllLinks()
Dim vLinkSources
Dim iLinkSource As Integer
Dim AnySheet As Worksheet
sPath = "C:\SOW\"
sName = Dir(sPath & "*.xls")
Do While sName < ""
Set bk = Workbook.Open(sPath & sName)
For Each AnySheet In ActiveWorkbook.Worksheets
ActiveWorkbook.Worksheets(AnySheet.Name) _
.Unprotect Password:="mypassword"
Next
vLinkSources = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(vLinkSources) Then
For iLinkSource = LBound(vLinkSources) To UBound(vLinkSources)
ActiveWorkbook.UpdateLink _
vLinkSources(iLinkSource), xlExcelLinks
Next
End If
For Each AnySheet In ActiveWorkbook.Worksheets
ActiveWorkbook.Worksheets(AnySheet.Name) _
.Protect Password:="mypassword"
Next
bk.Close Savechanges:=True
sName = Dir()
Loop
End Sub

In Microsoft Excel Objects (Sheet1) I added a Command Button and inserted
the following code:
===================================
Private Sub CommandButton1_Click()
UpdateAllLinks
End Sub

"Bill Manville" wrote in message
...
The reason may well be that there is no \ at the end of

sPath = " C:\Documents and Settings\Shane\My Documents\Harcourt
Assessments\password"

so you are looking for files called password*.xls in the Harcourt
Assessments folder.

If that is not the problem, it would be helpful if you told us in what
way it failed to work - any messages, any sign of it opening any files
etc.

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - respond to newsgroup



  #5   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming,microsoft.public.excel.setup,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 473
Default Opening Protected EXCEL worksheets to update linked data

should be
Workbooks.Open

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - respond to newsgroup



  #6   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.links,microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming,microsoft.public.excel.setup,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 30
Default Opening Protected EXCEL worksheets to update linked data

Bill,

Thanks for your keen eye -- works like a charm, except for the problem that
the Finance Folks have varying passwords on individual worksheets -- they'll
need to get together and decide on a universal (shared) password, but other
than that, the code works great.

Thanks again for your help.
==================================
"Bill Manville" wrote in message
...
should be
Workbooks.Open

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - respond to newsgroup



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I update data in 3 related files in Excel? Vellarian Excel Discussion (Misc queries) 0 March 2nd 06 06:17 AM
Excel worksheets become protected out of the blue Seng Excel Discussion (Misc queries) 0 February 22nd 06 06:47 PM
How do you protect hidden linked worksheets with in an Excel workb Newsgal Excel Discussion (Misc queries) 1 February 21st 06 08:49 PM
Inserting a new line when external data changes Rental Man Excel Discussion (Misc queries) 0 January 11th 06 07:05 PM
Dynamically create worksheets in Excel based off existing data? tlozier Excel Discussion (Misc queries) 1 September 10th 05 12:25 AM


All times are GMT +1. The time now is 06:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"