PDA

View Full Version : modify Users Template locations



asad
10-01-2017, 05:25 AM
Hi guys, I am a new user to word VBA, and This is my first post
I use 2 Normal template files in the Word program
- The first in this path: C:\Users\mohamed.rq\AppData\Roaming\Microsoft\Templates\
- The second in this path: C:\Users\mohamed.rq\AppData\Roaming\Microsoft\Templates\New
After the User Files Locations dialog box opens, how do I switch to the other path.
Please help, Do it for me Please
this is my code:

Sub FileLocations()
Dialogs(wdDialogToolsOptionsFileLocations).Display
' What am I doing then
' What am I doing then
' What am I doing then




End Sub

gmaxey
10-01-2017, 06:04 AM
Ignoring the question why would you want two Normal templates which seems abnormal,


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 10/1/2017
MsgBox GetUserTemplatePath
Options.DefaultFilePath(Path:=wdUserTemplatesPath) = _
"D:\My Documents\Word\Templates\Template Add-Ins\"
MsgBox GetUserTemplatePath
Options.DefaultFilePath(Path:=wdUserTemplatesPath) = _
"D:\My Documents\Word\Templates\"
MsgBox GetUserTemplatePath
lbl_Exit:
Exit Sub
End Sub
Function GetUserTemplatePath() As String
Dim fDlg As Dialog
Set fDlg = Dialogs(wdDialogToolsOptionsFileLocations)
With fDlg
.Path = "USER-DOT-PATH"
.Update
GetUserTemplatePath = .Setting
End With
End Function

Roderick
10-12-2017, 07:22 AM
Thanks, Greg for that info.

I was not specifically looking for it; just happened to be reading the post and thought "This is what I might just want in the future". So have made a note of your code.

asad
10-14-2018, 02:41 AM
Thank you very much, and please accept my apology.

gmayor
10-14-2018, 04:28 AM
I am not sure why an apology was necessary, and I am not sure whether Greg's code will work without restarting Word to load an alternative normal template from the revised location. Frankly it is better not to mess with the normal template and use document templates to create your documents. Recent versions of Word don't exactly help with that, so I produced an add-in which allows templates to be used readily from a variety of user customisable locations - https://www.gmayor.com/select_document_template.htm and a companion add-in which allows you to easily load (and unload) add-in templates also from a variety of locations https://www.gmayor.com/load_word_addins.htm