Solved

Save file over existing file with password

Posted on 2014-12-05
8
73 Views
Last Modified: 2014-12-09
I use the below code to save a file with a date and a password

ActiveWorkbook.SaveAs Filename:="\\ukancbdata02\S-gdata\AllFiles\Recon\London\Events\Consolidated Report\Consolidated " & Format(DateAdd("d", -0, Date), "YYYY") & ".xls", _
    FileFormat:=xlNormal, Password:="", WriteResPassword:="pact", _
        ReadOnlyRecommended:=True, CreateBackup:=False


What I need to do do is overwrite the file each day but because it is password protected the code returns an error.

Could an Expert provide me with the code that will enable me to save the file each day over the existing file with the password.
0
Comment
Question by:Jagwarman
  • 4
  • 3
8 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40482731
HI,

which PW is missing

ActiveWorkbook.SaveAs Filename:="\\ukancbdata02\S-gdata\AllFiles\Recon\London\Events\Consolidated Report\Consolidated " & Format(DateAdd("d", -0, Date), "YYYY") & ".xls", _
    FileFormat:=xlNormal, Password:="", WriteResPassword:="pact", _
        ReadOnlyRecommended:=True, CreateBackup:=False

Regards
0
 

Author Comment

by:Jagwarman
ID: 40482901
Hi Rgonzo, soory not sure I understand the question.

when the original file was saved, it was saved with a password. If I open the file manually I am asked for a password and then I get asked "Open as Read Only?"

So now I want to save over this file.

 Does this answer your question?
0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 40482921
I just created a simple file and saved with a password. I then closed the file and tried saving another file with the same name and it gave me the usual "File exists, Replace" warning to which I clicked Yes and the file overwrote with no problem.

Have you closed the original file before trying to Overwrite?

If you are doing changes in the open file which you want to save, just use "ActiveWorkbook.Save" command. The password will be retained for future use.

Thanks
Rob H
0
 

Author Comment

by:Jagwarman
ID: 40483176
Hi Rob,

If I open the original file and the save it down its fine.

If I create a new file and call it the same name it does not work.

So maybe it's not possible.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 32

Expert Comment

by:Rob Henson
ID: 40483218
That's exactly what I did. Created file and saved with password. Closed file, created new file and saved with same name, overwrote fine after confirming message.
0
 

Author Comment

by:Jagwarman
ID: 40486489
Hi Rob,

when I save outside of a Macro it does exactly what you say. When I try to get the Macro to save it I get error saying the file is Write protected.
0
 
LVL 32

Accepted Solution

by:
Rob Henson earned 500 total points
ID: 40486498
Bizarre, just tried it myself and got the same but got it to work using the following:

ActiveWorkbook.SaveAs Filename:= _
        "C:\Users\lu677d\Documents\Personal\EE\With Password.xlsx", FileFormat:= _
        xlOpenXMLWorkbook, Password:="", WriteResPassword:="pact", _
        ReadOnlyRecommended:=True, CreateBackup:=False

Open in new window


Note the format change. You just need to change the filename bit back to how you want it.

Thanks
Rob H
0
 

Author Comment

by:Jagwarman
ID: 40488681
Hi Rob thanks for working on this and sorting it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now