Quote:
Originally Posted by burniksapwet
I need it to be in a macro because the next step is creating a .bat for it that will automate doing it for multiple documents inside a folder. Thank you.
|
To process all documents in a folder, you'd use a macro (not a .bat file) like:
Code:
Sub ProcessDocuments()
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 & "\*.doc", vbNormal)
Do While strFile <> ""
If strFolder & "\" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With ActiveDocument 'wdDoc
.ActiveWindow.View.ShowHiddenText = True
With .Range
.Font.Hidden = True
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Hidden = False
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Highlight = True
.MatchWildcards = True
.Text = ""
.Replacement.Text = "^&^p"
.Execute Replace:=wdReplaceAll
.Text = "[^13]{2,}"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
.Copy
.PasteSpecial DataType:=wdPasteText
End With
.Range.Font.Hidden = False
.Close SaveChanges:=True
End With
End If
strFile = Dir()
Loop
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