• Environmental Variable for UsersAppdataroaming

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Environmental Variable for UsersAppdataroaming

    Author
    Topic
    #472888

    I am in word 2007 and need to modify a global word template to look to a user’s appdataroamingmicrosofttemplates folder for company specific templates.
    I have the following code defining the path
    Public Const strForms As String = “c:users%username%appdataroamingmicrosoftTemplatescompanyforms”
    I’ve tried to use Environ$(“Appdata”) & “…companyfirms”
    %appdata% & “…companyfirms”

    Then, the ribbon points to that location to pull the templates
    Sub OpenLtr(control As IRibbonControl)
    Documents.Add Template:=strForms & “timesheet.dotx”, _
    NewTemplate:=False, DocumentType:=0
    frmTime Show
    Unload frmTime
    End Sub

    I just can’t figure out how to define the variable for appdata regardless of the user name. The company has an outside tech firm managing their network and insists that I can’t point to c:prog filesmsofficeoffice12templates…. so that is not an option.

    Help anyone?
    Thx

    Viewing 8 reply threads
    Author
    Replies
    • #1254161

      Maybe…

      Function GetSpecialFolders(ByRef vFolder As Variant) As String
      Dim WSHShell As Object
      Set WSHShell = CreateObject(“WScript.Shell”)
      GetSpecialFolders = WSHShell.SpecialFolders(vFolder)
      Set WSHShell = Nothing
      End Function

      Sub WhatWhereHow()
      MsgBox GetSpecialFolders(“Templates”)
      ‘also try “Programs”
      End Sub
      ‘—
      Jim Cone
      Portland, Oregon USA
      commercial add-in

    • #1254170

      TechTrain,

      Am I missing something? {Wouldn’t be the first time} Why are you trying to point to the user’s C: drive for company specific templates? They should be on a server in a single place, e.g. one copy for all, and Word should be installed to point the “Workgroup Templates” to that location.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      • #1254207

        Am I missing something? {Wouldn’t be the first time}

        Gary,

        I warned you!

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

    • #1254177

      RG: Putting the company templates on a consistent location on each user’s C: drive can be a valid way to go, as well. One benefit of doing it that way is that users will continually have access to the company templates, whether they are currently working on or off the network.

      But either way, the template path should be consistent for all users.

      techtrain: Besides the complication of having to return an environmental variable in order to determine the correct template path, I think putting the templates into a user-specific location means that the documents will lose their connection to their originating templates, when they are passed among users.

      Do you observe this problem at your company? – that is, if User A creates a new document and then User B goes to work in it, does User B lose access to things like macros or Ribbon customizations, that are associated with the originating template?
      (based on your code sample, it looks like you have no code in the timesheet template, but instead are keeping code in a global template, so maybe the issue is moot…)

      Gary

    • #1254212

      The code for all templates lives in a company global template that is in the startup. There are a few reasons I can’t point the workgroup templates to a network path
      1) Users move with their laptops and there are network connectivity issues (don’t ask about that!) so I want them to have local access to the templates at all times
      2) I can’t put them in C:prog filems offoffice 12templates because users don’t have admin right on their machines so I can’t script it to place the company templates to that folder without visiting all 100 users
      3) i can’t edit workgroup templates on the fly if they are pulled from network. Presently, the templates are on a network share k:OfficeTemplates. If I need to modify a template and a user has it attached to an open document, I can’t access it right away.

      Soooo, I have a login script that copies all office templates to the local machine. Additionally, it copies a good copy of the officemaster.dotm to the startup.

      I thought that using Environ$(“APPDATA”) & “roamingmicrosoftTemplatesOfficeTemplates”
      would work….but it doesn’t!

      Thanks for any more insight!

      • #1254213

        I thought that using Environ$(“APPDATA”) & “roamingmicrosoftTemplatesOfficeTemplates”
        would work….but it doesn’t!

        Techtrain,

        I think you problem is with the extra Roaming – you just want to append “MicrosoftTemplatesOffice Templates”!

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

    • #1254215

      RG:
      Where is my extra roaming? It’s monday morning. I need a little more help ๐Ÿ™‚
      I don’t want it to go to appdatalocal, I need to specify appdataroaming.
      thx

    • #1254232

      Techtrain,

      Look at the graphic again. Environ$(“APPDATA”) return value includes the Roaming. Your code then appends a string starting with Roaming so you wind up with C:Users[USERID]AppDataRoamingroamingmicrosoftTemplatesOfficeTemplates.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1254245

      RG
      I think I need one of those frosty mugs with your emoticon!
      This is the old code
      Public Const strForms As String = “K:OfficeTemplates”

      This is what I can’t get:
      Public Const strForms As String = “Environ$(%APPDATA%)” & “MicrosoftTemplatesOfficeTemplates”

      If i use (“Appdata”) I get an unexpected end of statement error. This is the only iteration that does not give me a compile error

      Thanks for your patience

      • #1254250
        Code:
        Public Const strForms As String = "Environ$(%APPDATA%)" & "MicrosoftTemplatesOfficeTemplates"
        

        I think you don’t want quotes around Environ$(%APPDATA%) or Environ$(“APPDATA”) since that actually is a function you need to run rather than static text. Hard to tell from the context…

    • #1254252

      Techtrain,

      When you use Environ$ you need to enclose the variable name in ” ” not % %.
      Her you go have at it!

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1254254

      Can I not use the environ variable in a constant expression? I’m ready to give up!
      Thanks

      • #1254265

        Can I not use the environ variable in a constant expression? I’m ready to give up!

        Hmmm, I think that might be true, that the value assigned to a constant must be fixed at the time you write the code. Hence the name constant.

        Use a variable instead?

        Code:
        Dim strForms as String
        strForms = ...
    Viewing 8 reply threads
    Reply To: Reply #1254232 in Environmental Variable for UsersAppdataroaming

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel