Hello Fellows,
I want to Loop through a folder and remove all formatting of MS Word documents from Excel.
I am using below attached code, but it's not working. I am stuck with actual command execution.
Please help me in this regards
Thanks
I want to Loop through a folder and remove all formatting of MS Word documents from Excel.
I am using below attached code, but it's not working. I am stuck with actual command execution.
Please help me in this regards
Thanks
Code:
Sub clrfmt()
Dim wdapp As New Word.Application
Dim myDoc As Word.Document
Dim myFolder As String, strFile As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a folder"
.Show
.AllowMultiSelect = False
Tha If .SelectedItems.Count = 0 Then 'If no folder is selected, abort
MsgBox "You did not select a folder"
Exit Sub
End If
myFolder = .SelectedItems(1) & "\" 'Assign selected folder to MyFolder
End With
Application.ScreenUpdating = False
strFile = Dir(myFolder & "\*.doc", vbNormal)
While myFile <> ""
Set myDoc = wdapp.Documents.Open(Filename:=myFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With myDoc
ActiveDocument.Select
Selection.ClearFormatting
End With
myDoc.Close SaveChanges:=True
strFile = Dir()
Wend
wdapp.Quit
Set myDoc = Nothing: Set wdapp = Nothing: Set myWkSht = Nothing
Application.ScreenUpdating = True
End Sub