View Single Post
 
Old 01-17-2022, 02:46 PM
Venteux Venteux is offline Windows 10 Office 2019
Novice
 
Join Date: May 2021
Posts: 22
Venteux is on a distinguished road
Default

I have used this macro multiple times for different things and it's been great! However, I have two macros that I wanted to use it with, and I can't figure out why they're not working. When I run the macro on it's own for an active/open document, it works. But when I insert the code into this UpdateDocuments(), it doesn't work. The macro runs and I don't get any error messages, but when I open the individual files, nothing has been done to them. Am I doing something wrong?

I wanted to mark all documents in a specified folder as spelling and grammar checked already, and I wanted to accept all changes and stop tracking changes. This is the code I used:

Code:
Sub GrammarAndSpelling_Folder()

' GrammarAndSpelling_Folder macro that marks all of the documents in a specified folder as spelling and grammar checked already

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
	ActiveDocument.SpellingChecked = True
	ActiveDocument.GrammarChecked = True
      .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
The second one was:
Code:
Sub TrackChanges_Folder()

' TrackChanges_Folder macro that accepts all changes and stop tracking

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
    ActiveDocument.AcceptAllRevisions
    ActiveDocument.TrackRevisions = False
      .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
Reply With Quote