+ Reply to Thread
Results 1 to 14 of 14

Thread: How to get a closed and password locked excel workbooks creation date

  1. #1
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    How to get a closed and password locked excel workbooks creation date

    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.

  2. #2
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    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

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: How to get a closed and password locked excel workbooks creation date

    That should not clear your variables unless it causes an error that you don't handle.

  4. #4
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    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

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: How to get a closed and password locked excel workbooks creation date

    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.

  6. #6
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    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

  7. #7
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    Quote Originally Posted by romperstomper View Post
    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.
    Ah ok, so it didnt like the file name or something like that. then it throws everything off till i open the sheet again because the variables are all defined in an auto open routine.

  8. #8
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    but now it seems to disable these commands
            Application.DisplayAlerts = False
            Application.ScreenUpdating = False
    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.

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: How to get a closed and password locked excel workbooks creation date

    Where do those lines appear in your code and what are you trying to do?

  10. #10
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    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
    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.

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: How to get a closed and password locked excel workbooks creation date

    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

  12. #12
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    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.

  13. #13
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    also i was wondering if you could tell me abotu the
     On Error
    command 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.

  14. #14
    Registered User
    Join Date
    07-22-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: How to get a closed and password locked excel workbooks creation date

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0