Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-17-2022, 04:55 AM
Itsjustbeej Itsjustbeej is offline Using the user profile variable for a document template path Windows 10 Using the user profile variable for a document template path Office 2016
Novice
Using the user profile variable for a document template path
 
Join Date: Apr 2021
Location: NC
Posts: 16
Itsjustbeej is on a distinguished road
Default Using the user profile variable for a document template path

Hi folks,



My company has a toolbar template used for specific documents we write. IT wants to push it to each user via OneDrive, which means the path to the toolbar will be different for each user. Something like this:

C:\Users\username\Regulatory - Templates\Toolbar.dotm

Where username is the user's login name. I know we should be able to do this using the %USERPROFILE% variable, but when I've tested it on my machine it doesn't work. Thus, currently

C:\Users\myname\Regulatory - Templates\Toolbar.dotm

works (where myname = my actual login name), but if I put in

C:\Users\%USERPROFILE%\Regulatory - Templates\Toolbar.dotm

it doesn't. I get an error that the template can't be found.

What's the correct syntax, or what do I need to change to make this work?

Thanks in advance,

Beej
Reply With Quote
  #2  
Old 03-17-2022, 05:13 AM
gmayor's Avatar
gmayor gmayor is offline Using the user profile variable for a document template path Windows 10 Using the user profile variable for a document template path Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following should work for you
Code:
Dim FSO As Object
Dim sDoc As String
    sDoc = Environ("USERPROFILE") &  "\Regulatory - Templates\Toolbar.dotm"
    'MsgBox sDoc
    Set FSO = CreateObject("Scripting.FileSystemObject")

    If FSO.FileExists(Environ("USERPROFILE") &  "\Regulatory - Templates\Toolbar.dotm") Then
        Documents.Add sDoc
    Else
        MsgBox "The toolbar template is not found"
    End If
    Set FSO = Nothing
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-17-2022, 05:31 AM
Itsjustbeej Itsjustbeej is offline Using the user profile variable for a document template path Windows 10 Using the user profile variable for a document template path Office 2016
Novice
Using the user profile variable for a document template path
 
Join Date: Apr 2021
Location: NC
Posts: 16
Itsjustbeej is on a distinguished road
Default

That's great, but I guess I needed to provide more detail. We have about 125 documents which use this toolbar. What I need, I think, is the correct syntax for use in the Templates and Add-ins "Document template" field. Currently I have the path hard-coded so that every one of these documents looks in:

C:\Users\myloginname\Regulatory - Templates\Author.dotm

for the Document Template. It works for me, but I have over 130 users and we can't have each person change the location to their user name, plus as the document is passed from user to user each person will have to change it again.

I've attached a screen shot to show how it's configured on my machine. Basically I want to replace "myloginname" with the %USERPROFILE% variable in that field so it changes from user to user.

Thanks again for any help you can provide.
Attached Images
File Type: jpg Dialog.jpg (40.3 KB, 15 views)
Reply With Quote
  #4  
Old 03-17-2022, 05:55 AM
macropod's Avatar
macropod macropod is offline Using the user profile variable for a document template path Windows 10 Using the user profile variable for a document template path Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: Incorporating the User Profile location into a document template path | Microsoft Office Forums
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-17-2022, 07:26 AM
Charles Kenyon Charles Kenyon is offline Using the user profile variable for a document template path Windows 10 Using the user profile variable for a document template path Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,536
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Consider using the Workgroup Templates settings which can be accessed in vba.
Code:
Options.DefaultFilePath(wdWorkgroupTemplatesPath)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the user profile variable for a document template path how to determine the full path of the template from which a document was created? XmisterIS Word VBA 4 08-28-2024 03:32 PM
Using the user profile variable for a document template path Insert variable in path name bearcublandon Word VBA 6 01-03-2019 08:17 PM
Windows 10 (Microsoft) has named my User Profile folder. wondermuse Windows 0 01-04-2017 10:00 PM
Using the user profile variable for a document template path User input to a variable on the document dsm1995gst Word VBA 1 09-03-2013 03:43 PM
attaching (relative,logical or virtual) path to template word document wissam Mail Merge 0 08-04-2009 05:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:14 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft