Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Feb 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filename Counter (Word 2003)

    I found the following code I can use to create sequential filenames for documents automatically. How do I get the contents of the Order variable into the strFileName variable?

    Sub AutoNew()

    Order = System.PrivateProfileString("C:Settings.Txt", "Macrosettings", "Order ")
    If Order = "" Then
    Order = 10000000
    Else
    Order = Order + 1
    End If

    System.PrivateProfileString("C:Settings.Txt", "Macrosettings", "Order") = Order
    ?
    ActiveDocument.SaveAs (strFileName)
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Filename Counter (Word 2003)

    You could use

    strFileName = Order & ".doc"

    above the line that saves the record. Is this related to your question <post#=458421>post 458421</post#> in the Word forum?

  3. #3
    New Lounger
    Join Date
    Feb 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Counter (Word 2003)

    Thanks, it was a typo causing me problems. Yes, it is related to the other post, should I delete that one?

    I have one more question, how do I get the user initials into a variable? I tried:

    strUser=Application.UserInitials

    but that did not work.

    Thanks again.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Filename Counter (Word 2003)

    I have locked the thread in the Word forum, with a link to this one.

    strUser = Application.UserInitials should work, what is the problem you have with it?

  5. #5
    New Lounger
    Join Date
    Feb 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Counter (Word 2003)

    Thank you for the help. I did get the numerical, incrementing macro to work and set it as an AutoNew macro to automatically generate filenames.

    I would like to know how to use the date and time in the following format instead of the incrementing numbers:

    yyyymmddhhmmss

    as the filename. I can set the format and insert it into a document, but need to know how to insert it into a variable instead.

    Thanks again!

  6. #6
    New Lounger
    Join Date
    Feb 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filename Counter (Word 2003)

    Okay, figured it out, thank you! I used:

    Dim strFileName As String

    strFileName = Format(Now, "yyyyMMddHHmmss") & Application.UserInitials & ".doc"
    ActiveDocument.SaveAs (strFileName)

Posting Permissions

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