Consulting

Results 1 to 4 of 4

Thread: Macro to add / update document version

  1. #1
    VBAX Regular ShogunPatch's Avatar
    Joined
    Jan 2018
    Location
    London
    Posts
    14
    Location

    Macro to add / update document version

    So here's the thing. We are finally in the process of migrating our cranky old on-prem file server to Sharepoint Online / Office 365.
    As I understand it, one of the many advantages of Sharepoint is that it automatically maintains a save history of all files. As I understand it this means if I'm writing a report in Word and over the course of the 3-4 weeks that I take to write it, I save it x-hundred times, if I find I've made a mistake I can go back to any previous version of the document I like. This is great, because our current server does not have this feature (or if it does, it is not setup properly) and so our current practice is to re-save every incremental version of a document draft with an appended date reference and so end up with many dozens of different named versions.

    So against the above back-drop what I would like (I think) is to a add a unique reference field - effectively a version number - to my document (to my template's footer, say), so that whenever I am looking at a print-out, I can quickly and easily go back to that specific draft. I'm thinking the easiest would be to use the SaveDate field in the format yyMMdd-HHmmss; that, together with the document name should allow me to uniquely identify the document/version in question. But of course for this to work I would need to ensure that the document was automatically saved and that field updated every time the document was printed.

    Might anyone be able to provide me with some code to do the above, and explain to me like I'm a five-year old exactly how to set it up?

    Or else if anyone has a better, more elegant solution to the problem I'd be equally happy with that.

    Many thanks.

  2. #2
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    215
    Location
    This is what I use when I need to capture those types of details. How to make it happen for every document I'm not sure.

    [CODE]Sub OnCloseAddFooter()

    DimFilename AsString
    DimSec As Section

    Filename= ThisDocument.FullName

    ForEach Sec InActiveDocument.Sections
    WithSec.Footers(wdHeaderFooterPrimary)
    .Range.InsertDateTime DateTimeFormat:="MM/dd/yyyy H:mm", InsertAsField:= _
    True,DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern
    .Range.Text = .Range.Text &Filename
    .PageNumbers.Add
    EndWith
    NextSec

    EndSub
    [/CODE]

  3. #3
    VBAX Regular ShogunPatch's Avatar
    Joined
    Jan 2018
    Location
    London
    Posts
    14
    Location
    Hi Kilroy, thank you for taking the time to reply.
    My knowledge of VBA is pretty basic, but I think I'm right in saying that the code you've suggested automates the process of inserting the date and time, file name and page number into the footer of each section in my document, is that right? If so, thank you but that's not what I am after as my template already includes all the info I want in the footer. My issue is how to get the document to automatically save (and have the date/time automatically refresh in the process) each and every time the document is printed. Any ideas?

    Many thanks.

  4. #4
    VBAX Regular ShogunPatch's Avatar
    Joined
    Jan 2018
    Location
    London
    Posts
    14
    Location
    UPDATE

    I think I've sorted the issue of getting the date and time to update automatically. If so, my only problem now is how to get the document to save automatically each time it is printed. I've checked various forums and online articles, e.g.
    http://www.vbaexpress.com/forum/show...=save+on+print
    http://www.vbaexpress.com/forum/show...=save+on+print
    https://wordmvp.com/FAQs/MacrosVBA/AppClassEvents.htm
    I'm struggling to understand or get any of their proposed solutions to work; even so, I cannot help feeling that what I'm trying to do is probably really simple if you know what you're doing. The trouble is, I don't!

    Any instructions would be gratefully received...

Tags for this Thread

Posting Permissions

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