That way you get a message about the new location. I have learned, through this experience with you, to first move the thread and then respond. I am still learning this moderator business. I hope I answered your questions about templates, or at least gave you the resources to understand how they work in the new thread. I put a link back to this thread in case anyone wanted the context in which you were asking. I understand that it has to do with the same problem in your work with Word, but it really did not seem like a vba question. Those do not seem to be vba questions and might better be answered in the general thread.Īnswers to those questions might be more easily found by others with similar questions looking in the future in that thread. This was answered but you had questions about deleting styles and about how templates work. The original post was about applying styles from the normal template to all files in a folder using vba. I thought that if you tried to respond to my response, you would see the new thread in the general Word forum. I don't mean any offence, but a note should really have been left letting me know that. Also, any style with the same priority level will fall into alphabetical order anyway so just setting Normal to 99 doesn't mean much if all the other styles are also set to 99. If you are showing styles in alphabetical order then the style's priority setting is ignored. If the custom styles in NormalTemplate don't exist in ThisDocument BUT they are based on styles that do, then those styles may not appear the same as they do in NormalTemplate.įiddling the priority settings only make sense if you have chosen to display the styles in that order (by setting options to display list order 'As Recommended'). The following lines would give you all the style definitions from ThisDocument + the aliases and custom styles from NormalTemplate. Note that running two consecutive lines to import styles from two different templates has some gotchas. Normal is a special built-in style but "underline" and "No-spacing" would be either custom styles (or aliases added to a built-in style depending on your settings). Visibility = True means that the style doesn't appear in your styles list) Visibility property to True (yes, it is backwards. For instance, you can hide any styles by setting their.
You can either configure the styles exactly as you want in the templates so that the settings get imported OR you can run more code to undo the settings you didn't want after you import the styles. This includes the visibility, priority etc. When you copy styles, you get everything about those styles in the document.
But if you know how to differentiate the two then it may well come in useful later.
I only need the heading styles at the minute, but it doesn't bother me that all styles are copied. CopyStylesFromTemplate (ThisDocument.FullName)Īndrew, nice to hear from you again after my promised holiday CopyStylesFromTemplate (NormalTemplate.FullName) If (Not oFolder Is Nothing) Then GetFolder = Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) , Name:="Default", Object:=wdOrganizerObjectStyles
" C:\Users\MyName\Documents\FolderName\FileName.docx" _ 'Call your other macro or insert its code here
Set wdDoc = Documents.Open(FileName:=strFolder & "" & strFile, AddToRecentFiles:=False, Visible:=False) If strFolder & "" & strFile strDocNm Then StrFile = Dir(strFolder & "\*.docx", vbNormal)
StrDocNm = ActiveDocument.FullName: strFolder = GetFolder Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document