Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default unlock workbooksin hundred of excel files

Dim bk as Workbook, sPath as String
Dim sStr as String
sPath = "C:\MyFolder\"
sStr = Dir(sPath & "*.xls")
do while sStr < ""
set bk = workbooks.Open( filename:=sStr, _
password:="ABCD")
' work with bk
bk.close Savechanges:=False
sStr = Dir()
Loop

--
Regards,
Tom Ogilvy



"guilhaume " wrote in message
...
Hi all,

I'm trying to get data from hundred of excel files with Java.
The workbooks are locked (so I cannot get the data, and there is no
Java-solution), I know the password, but I don't want to unlock them
manually :)

Does anybody know a script (I don't know vb very well...) that can do
this job for me?

reguards


---
Message posted from http://www.ExcelForum.com/



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default unlock workbooksin hundred of excel files

Thx a lot, but I think I didn't explain very well what I wanted to do
:)
It is to say:
have a script that takes out the workbook's protection without havin
to open the excel file with Office and do 'Utils', 'Protection'
'Unprotect the workbook' (problably the menu names are wrong, as I a
french I tested a translation... ;))

in fact I wanted a script like that:

for all the files f in the directory d do
f.unprotectWorkbook()
end

reguard

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default unlock workbooksin hundred of excel files

Dim bk as Workbook, sPath as String
Dim sStr as String
sPath = "C:\MyFolder\"
sStr = Dir(sPath & "*.xls")
do while sStr < ""
set bk = workbooks.Open( filename:=sStr, _
password:="ABCD")
Application.DisplayAlerts = True
bk.SaveAs bk.FullName
Application.DisplayAlerts = False
bk.close Savechanges:=False
sStr = Dir()
Loop

--
Regards,
Tom Ogilvy

"guilhaume " wrote in message
...
Thx a lot, but I think I didn't explain very well what I wanted to do
:)
It is to say:
have a script that takes out the workbook's protection without having
to open the excel file with Office and do 'Utils', 'Protection',
'Unprotect the workbook' (problably the menu names are wrong, as I am
french I tested a translation... ;))

in fact I wanted a script like that:

for all the files f in the directory d do
f.unprotectWorkbook()
end

reguards


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default unlock workbooksin hundred of excel files

sorry - that was file level protection. For workbook protection as you
describe

Dim bk as Workbook, sPath as String
Dim sStr as String
sPath = "C:\MyFolder\"
sStr = Dir(sPath & "*.xls")
do while sStr < ""
set bk = workbooks.Open( filename:=sStr)
bk.Unprotect Password="ABC"
bk.close Savechanges:=True
sStr = Dir()
Loop

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
Dim bk as Workbook, sPath as String
Dim sStr as String
sPath = "C:\MyFolder\"
sStr = Dir(sPath & "*.xls")
do while sStr < ""
set bk = workbooks.Open( filename:=sStr, _
password:="ABCD")
Application.DisplayAlerts = True
bk.SaveAs bk.FullName
Application.DisplayAlerts = False
bk.close Savechanges:=False
sStr = Dir()
Loop

--
Regards,
Tom Ogilvy

"guilhaume " wrote in message
...
Thx a lot, but I think I didn't explain very well what I wanted to do
:)
It is to say:
have a script that takes out the workbook's protection without having
to open the excel file with Office and do 'Utils', 'Protection',
'Unprotect the workbook' (problably the menu names are wrong, as I am
french I tested a translation... ;))

in fact I wanted a script like that:

for all the files f in the directory d do
f.unprotectWorkbook()
end

reguards


---
Message posted from http://www.ExcelForum.com/





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default unlock workbooksin hundred of excel files

thanks a lot to all of you!

I think it will greatly help me

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default unlock workbooksin hundred of excel files

hey,
I was on holiday..that's why I didn't test the code earlier!
when I try to run this code:

Private Sub Form_Load()
Dim bk As Workbook, sPath As String
Dim sStr As String
sPath = "G:\gmp\fichiers xls\"
sStr = Dir(sPath & "*.xls")
Do While sStr < ""
Set bk = Workbooks.Open(FileName:=sStr)
bk.Unprotect Password = "2132"
bk.Close Savechanges:=True
sStr = Dir()
Loop
End Sub

I have the following error
(in french for those who will understand)
Erreur d'execution '1004'
toto.xls est introuvable, verifiez l'orthographe du nom du classeur e
la validité de l'emplacement
(here is an english translation ;) )
Runtime error '1004'
toto.xls not found, verify the workbook name and the path

but toto.xls exists at the specified path....

I searched on the net and I didn't find what it meant!

Could you help me please?
regards
guilhaum

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default unlock workbooksin hundred of excel files

guilhaume

I'm pretty sure that your file name is not correct.

From yur code I read

sPath = "G:\gmp\fichiers xls\"


which should be

sPath = "G:\gmp\fichiers.xls"


(no trailing slash and a dot for the file extension)

Hope it helps

--alexT
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
Hundred Seperator in Excel Kshitij Excel Discussion (Misc queries) 2 August 11th 09 09:57 AM
Combining a few hundred excel files into one [email protected] New Users to Excel 1 June 19th 07 06:25 PM
how do i password protect an .xls file? how do i unlock it for automation. e.g. want to unlock and access a .xls from another .xls macro. Daniel Excel Worksheet Functions 1 June 24th 05 02:59 PM
Way to change a single line of vb code in several hundred excel files? bball887 Excel Programming 2 December 16th 03 03:24 PM
Way to change a single line of vb code in several hundred excel files? Alex[_13_] Excel Programming 0 December 15th 03 06:13 PM


All times are GMT +1. The time now is 07:00 AM.

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"