Consulting

Results 1 to 6 of 6

Thread: Changing Author and Last Modified By

  1. #1

    Changing Author and Last Modified By

    I was asked to produce a feature that replaces the author and last modified/saved by document properties of any Word document.
    The former is easy enough, and for the latter i figured I could simply change the Office user name, save the file and then restore the user name to its original state.
    The below code seems to work just fine for me, but when I tested it on other computers the author was changed but not the last modified by.
    Does anyone have any idea why this is? Grateful for any pointers/suggestions on how to sort out the code or reach the same result in another way!

    Sub ChangeAuthor()
        Dim Author As String
        Dim orig As String
        Dim Doc As Document
        Author = InputBox("Enter the new document author name.")
        orig = Application.UserName
            With Dialogs(wdDialogFileOpen)
            If .Display Then
                If .Name <> "" Then
                    Set Doc = Documents.Open(.Name)
                End If
            Else
                MsgBox "No file selected"
            End If
        End With
        Application.UserName = Author
        With Doc
            .BuiltInDocumentProperties("Author") = Author
            .Saved = False
            .Save
            .Close
        End With
    Application.UserName = orig
    MsgBox ("Done!")
    End Sub

  2. #2
    The last saved by doc property is not user editable, so if you want to make the last saved by name the same as the author name, then you will have to save it twice in order to replace the value in the last saved by field.
    With Doc
            .BuiltInDocumentProperties("Author") = Author
            .Saved = False
            .Save
            .Saved = False
            .Save
            .Close
        End With
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,046
    Location
    Graham,

    I'm missing something. I tinkered withi this yesterday and nothing I did has any effect on the the Last author property including your code:

    cratchMacro()
    With ActiveDocument
      MsgBox .BuiltInDocumentProperties("Last author")
        .BuiltInDocumentProperties("Author") = "Joe"
        '.BuiltInDocumentProperties("Last author") = "Joe" - no effect.
        .Saved = False
        .Save
        .Saved = False
        .Save
        MsgBox .BuiltInDocumentProperties("Last author")
        .Close
    End With
    
    lbl_Exit:
      Exit Sub
    End Sub
    After running and re-running, both msgboxes return me and not Joe.
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,046
    Location
    Graham,

    I figured out the reason why nothing was working. I was signed in so "Last author" is determined by the Windows LiveID username and not the Application.Username. After I logged out the follow worked. Note - There was no need to save twice:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim strUserName As String
      strUserName = Application.UserName
      Application.UserName = InputBox("Enter new author")
      With ActiveDocument
        .BuiltInDocumentProperties("Author") = Application.UserName
        .Save
      End With
      Application.UserName = strUserName
      ActiveDocument.Close
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    Ah, that would explain it Greg. Thank you both for investigating! Marking the thread "solved".

  6. #6
    A follow up: Note that if (through FILE > Options > Trust Center [Trust Center Settings ...] > Privacy Options) the document property box in front of Remove personal information from file properties on save is unchecked, then the Author name will be made blank when the document is saved, and the names of the authors of comments and alterations will be replaced by Author. More information: https://www.isumsoft.com/office/clea...-document.html. In my case, I was collaborating on the translation and revision of a document, and losing the information about authors (original, of comments, of alterations, ...) was highly frustrastring, until I plunged into the Trust Center Settings and unchecked Remove personal information from file properties on save.

Posting Permissions

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