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 PASSWORD PROTECTED FILE

MyXL.Workbooks.Open Filename:=xlFile, password:="ABCD"

--
Regards,
Tom Ogilvy



Gary B wrote in message
...
Hi,

I have an Access app that provides data for an Excel
Pivot Table.

Within the Access app, I wish to open the Excel file, and
update the pivot table, then save the Excel file.

The Excel file is password protected.

I use the following code, which works fine for
unprotected Excel files. How do I amend the code to pass
the password, (which I need to do twice) ?

Sub pwfile()
Dim MyXL As Object, xlFileAttribute As String
Dim xlFile As String, xlpw As String

DoCmd.SetWarnings False

xlFile = "c:\pw.xls"

'Set file attribute
xlFileAttribute = GetAttr(xlFile) ' Returns 1.
If xlFileAttribute = 1 Then
SetAttr (xlFile), vbNormal
End If

'Defer error trapping.
'If the application isn't running, an error occurs.
On Error Resume Next
Set MyXL = GetObject(, "Excel.Application")
Set MyXL = CreateObject("Excel.Application")

'Clear Err object in case error occurred.
Err.Clear

'Disarm all warnings
MyXL.Application.DisplayAlerts = False
MyXL.Application.AlertBeforeOverwriting = False
MyXL.Application.Visible = True
MyXL.Workbooks.Open (xlFile)

'Update Pivottables and Save the File

MyXL.Application.Activeworkbook.Sheets
("sheet1").Select
MyXL.Application.ActiveSheet.Range("A16").Value
= "opened"
MyXL.Application.Activeworkbook.Save
MyXL.Application.Activeworkbook.Close

'Save Excel file, close & destroy all Excel objects
'Arm all warnings before quiting Excel
MyXL.Application.DisplayAlerts = True
MyXL.Application.AlertBeforeOverwriting = True
MyXL.Application.Quit
Set MyXL = Nothing

End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default PASSWORD PROTECTED FILE


Works great, but also need to open for "write" purposes.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default PASSWORD PROTECTED FILE

Look in Excel VBA help for the workbook.open event. There are several
password option arguments. You should be able to open it and do what you
want by supplying the correct password.

--
Regards,
Tom Ogilvy


"Gary Burke" wrote in message
...

Works great, but also need to open for "write" purposes.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
XLS password protected file JacquesT Excel Discussion (Misc queries) 5 December 25th 08 02:02 PM
Password protected Excel File IT Service Agent Excel Discussion (Misc queries) 1 May 20th 08 07:34 PM
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. Daniel Excel Worksheet Functions 0 June 23rd 05 11:56 PM
bypass password when update linking of password protected file Yan Excel Discussion (Misc queries) 1 February 7th 05 11:29 PM
Save protected file into unprotected file without password Paul Excel Programming 3 August 2nd 03 05:17 PM


All times are GMT +1. The time now is 04:46 PM.

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

About Us

"It's about Microsoft Excel"