Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up Best method to point to network location for new document based on Word template

    Hello,

    I'm intermediate VBA. Is there a more reliable/best practice method to pointing to a Word template for a new document other than hardcoding such as Scripting.FileSystemObject or something? Currently it's hard coded to local drive with variable for user's Windows login name. I want to point to a shared folder on the network.

    Function GetUserName() As String

    Username = Trim(Environ$("Username")) 'Get username

    End Function.
    --------------------------------------------------------------------------------
    Sub CreateDoc

    Application.Documents.Add("C:\Users\" + Username + "\Documents\Custom Office Templates\FAR-DFAR.dotx", False, wdNewBlankDocument)

    End sub

    Thanks for your help.

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Do you mean like:
    Code:
    Sub CreateDoc
    Documents.Add("C:\Users\" & Environ("Username") & "\Documents\Custom Office Templates\FAR-DFAR.dotx", False, wdNewBlankDocument)
    End Sub
    which doesn't require using the FileSystemObject, or are you trying to specify a network location?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,637
    Thanks
    115
    Thanked 650 Times in 592 Posts
    Try this:

    Code:
    Sub CreateDoc
        Documents.Add Template:="\\server1\IT\FAR-DFAR.dotx"
    End Sub
    Replace the path with your network path and folder that contains the template. You do not need the other parameters as they are default.

    HTH,
    Maud

Posting Permissions

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