Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jun 2003
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Save current date in file name (Word 2000)

    How would I automate my macro to save the document with the current date in the file name? I need the date in the file name so that another program can use this information to print out a log of typed files afterward.

    My macro is:
    ' This paragraph automatically saves the report with the predefined variables assigned to the report header'

    ChangeFileOpenDirectory "D:CLIENT REPORTS"
    ActiveDocument.SaveAs FileName:=vIPatient & "-" & vID & "-" & _
    "JB" & ".doc", FileFormat:=wdFormatDocument, _
    LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
    :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
    SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    False

    The saved file looks something like this:
    BARNABY JONES-12345-JB (PATIENT NAME, ID#, & AUTHOR'S INITIALS)

    I would like to have the date automatically added to the file name so that it looks like this:
    BARNABY JONES-12345-JB-OCT 30 (The date does not have to be in that exact format, just as long as I have it in the file name)

    I have tried putting
    ActiveDocument.SaveAs FileName:=ActiveDocument.Variables("DocName") & " " & _
    Format(Now, "mm-dd-yyyy") & ".doc"
    into the code, but it does not work regardless of how I try to write it.

    Any help would be appreciated!

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Save current date in file name (Word 2000)

    Try using <code>ActiveDocument.Name</code> instead of <code>ActiveDocument.Variables("DocName")</code>

    StuartR

  3. #3
    Star Lounger
    Join Date
    Jun 2003
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save current date in file name (Word 2000)

    It still isn't working for some reason. I'm guessing I don't need to declare this as dim since it is already a global variable?

    I've tried:

    ActiveDocument.SaveAs FileName:=vIPatient & "-" & vID & "-" & _
    "JB" & Format(Now, "mm-dd-yyyy") & ".doc"

    AND also adding the statement by itself below the original code.

    Am I missing something here?

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Save current date in file name (Word 2000)

    So long as vIPatient and vID are string variables with reasonable content then I can't see the problem.
    Have you tried single stepping the code? What error message do you get.

    I'm not sure what Global Variable you are talking about, but it would be worth declaring a string as
    <code>Dim strFilename as String</code>

    so you could use
    <code>strFilename = vIPatient & "-" & vID & "-" & "JB" & Format(Now, "mm-dd-yyyy") & ".doc"</code>

    and see what value you are trying to use for saving the file.

    You could also use watchpoints to make sure you know the values of vIPatient and vID just before you use them.

    StuartR

  5. #5
    Star Lounger
    Join Date
    Jun 2003
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save current date in file name (Word 2000)

    It worked all along. The brain child that I am, I was using the actual macro and not the "test" macro.

    Thank you for your help!

Posting Permissions

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