In the macro I need the creation date of the excel file to log it for filing. The only problem is some of them are password protected, this doesn't effect what I am trying to do I just need the creation date, not the modified date for an Excel file. I do not have the passwords so i can't use the normal active workbooks method I dont think. the only ofther way I found was to use the sytem info object declaration but that way clears the rest of the publicly defined variables being used in the macro.
Thanks for yalls help.
Last edited by alexthapyro; 07-26-2011 at 12:17 PM.
I couldnt get it to work because of not being able to open the files,
Activeworkbboks.BuiltinDocumentProperties("Creation Date")
And the segment below keeps clearing all of my variables.
'This creates an instance of the MS Scripting Runtime FileSystemObject class Set oFS = CreateObject("Scripting.FileSystemObject") oFS.GetFile(strFilename).DateCreated
That should not clear your variables unless it causes an error that you don't handle.
What exactly does that mean? I had that segment of code in my macro and only after it was run do I get any problems with the variables.
I had it write to a variable to use for later then wrote that variable to a cell just to check the format and that it was working and it seemed to work fine every time because the date would be correct.
Last edited by alexthapyro; 07-25-2011 at 11:06 AM. Reason: adding more info
I mean that unless it causes a run time error which pops up a message that you then dismiss, it should not reset any of your variables.
Ok. now I am really confused, it seems to actually be alright even though this morning it wasn't and it wanst throwing errors. Its working now but it is has compleatly caused Excel to crash twice now, all the way out to where the document recover comes up and asks if you would like to send a report. any more ideas would be helpful.
As of now this is my exact code.
Sub unlock_file() File_name = Cells(17, 11).Value Set oFS = CreateObject("Scripting.FileSystemObject") Cells(1, 1) = oFS.GetFile(mypath + "\" + File_name).DateCreated End Sub
but now it seems to disable these commands
It is still asking for the do you wish to overwrite the file daialoge which I dont want it to ask I just want it to do it.Application.DisplayAlerts = False Application.ScreenUpdating = False
Where do those lines appear in your code and what are you trying to do?
If possible they told me to see if there is a way to open and close the files even if they are password protected and add data to them. so i am just doing proof of concept so I wanted to open the file then add a cell and save the file either with the same or a new password. So it works except when it does up to save it keeps asking for the save as dialoge and I dont want that as an option because in the future it may be processing lots of files.Sub unlock_file() Application.DisplayAlerts = False Application.ScreenUpdating = False File_name = Cells(17, 11).Value code = Cells(17, 12).Value code2 = Cells(17, 13).Value Set oFS = CreateObject("Scripting.FileSystemObject") date_created = oFS.GetFile(mypath + "\" + File_name).DateCreated Workbooks.Open Filename:= _ mypath + "\" + File_name, Password:=code, WriteResPassword:=code Cells(1, 1) = date_created ActiveWorkbook.SaveAs Filename:= _ mypath + "\" + File_name, FileFormat:=xlNormal, _ Password:=code2 , WriteResPassword:=code2 , ReadOnlyRecommended:=False, _ CreateBackup:=False Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub
Try:
Sub unlock_file() Application.ScreenUpdating = False File_name = Cells(17, 11).Value code = Cells(17, 12).Value code2 = Cells(17, 13).Value Set oFS = CreateObject("Scripting.FileSystemObject") date_created = oFS.GetFile(mypath + "\" + File_name).DateCreated Workbooks.Open Filename:= _ mypath + "\" + File_name, Password:=code, WriteResPassword:=code Cells(1, 1) = date_created Application.DisplayAlerts = False ActiveWorkbook.SaveAs Filename:= _ mypath + "\" + File_name, FileFormat:=xlNormal, _ Password:=code2 , WriteResPassword:=code2 , ReadOnlyRecommended:=False, _ CreateBackup:=False Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub
Yep that did the trick. I didn't realise the location would matter but I guess the new window needs the proporty not the current one.
Thank you for your help. How all am I supposed to mark a topic as solved, just through the avanced edit of the post. Also can you give people thanks or rate them on this forum, one of my other forums is like that.
also i was wondering if you could tell me abotu thecommand so far I have just seen the goto or the resume next after it. Would using that error command clear my variables. I am wondering because if the user lists the wrond password the document will not open. I would like to mark that document somehow and then keep cycling if possible.On Error
Does anyone else have any inputs on the error message in junction witht he code to eliminate the loss of the data stored in the variables if one of the files is not found.
Thanks for the future help
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks