View Single Post
 
Old 10-11-2020, 08:50 PM
John 4 John 4 is offline Windows 10 Office 2013
Advanced Beginner
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Smile

Many thanks Charles,
It's a pity you didn't look at the code I provided. It was almost all Macropod's, just a small part in the middle from me. I reckon someone like you could have fixed it directly in a lot less time than it took you to type your post. But I suppose your thinking is that one of those other options would take care of numerous future problems for me.

However I've been at those link locations before - although what's offered may be very useful in some areas; from memory, the Find and Replace function is very drastically reduced whereas with Macropod's macro you can use Find and Replace fully functional (just record or code what you want it to do and then place it in the middle of Mac's macro). As far as I can tell, the code I have is far more useful (for Find/Replace at least).

I used the 2 lines of code you provided to get my (Macropod's) code working. Here it is for anyone who may benefit (and it seems from the thread views that some are interested):


Code:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName: strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
  If strFolder & "" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc

      'Call your other macro or insert its code here
    .CopyStylesFromTemplate (NormalTemplate.FullName)
    .CopyStylesFromTemplate (ThisDocument.FullName)
        
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

Andrew, nice to hear from you again after my promised holiday

I only need the heading styles at the minute, but it doesn't bother me that all styles are copied. But if you know how to differentiate the two then it may well come in useful later.

Thank you both.
Reply With Quote