C
Carlos Chalhoub
Hi listmates,
I am using an application called "Robohelp for Word" to generate a Webhelp
system. During the generation, Robohelp transforms Word documents into HTML
files. The problem is that the HTML code generated is unconventional, and we
need to provide a clean code to our clients. So I was asked to write a
search and replace macro that will scan more than 3000 files and make the
appropriate adjustments.
Problem:
Sometimes the search string reaches beyond the 255 characters limit and I am
not sure how to make it accept more. I read somewhere that I need to use the
"InStr" function, but I don't know how.
Thanks for any help.
Carlos
-------------- START OF CODE-----------------------
Sub FixHTMLCode()
' Macro created by Carlos Chalhoub
' This macro fixes HTML code in all files in a directory
Dim strFolderName As String
' Specify the location of the folder
strFolderName = BrowseFolder("Specify the path to the folder containing the
files.")
If Right(strFolderName, 1) <> "\" Then
strFolderName = strFolderName & "\"
End If
With Application.FileSearch
.FileName = "*.htm"
.LookIn = strFolderName
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
If .Execute <> 0 Then 'start search, and if any files found then
proceed...
For i = 1 To .FoundFiles.Count 'loop through all files in folder
Documents.Open FileName:=.FoundFiles(i), ConfirmConversions:=False,
Format:=wdOpenFormatText
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = _
"(\<P class=""List"" \>\<FONT style=""font-family:'Symbol';
font-size:10pt; "" \>·\</FONT\>\<span style=""font-size:8pt;
font-family='Times New Roman'; letter-spacing=0pt;
font-weight=normal;""\> \</sp
an\>)(*)(\</p\>)"
.Replacement.Text = _
"<ul { list-style: outside; margin-bottom:3.00pt }
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.Close SaveChanges:=wdSaveChanges
Next i
Else: Exit Sub
MsgBox "There were no files found."
End If
End With
End Sub
-----------------------------END OF CODE-------------------------------
I am using an application called "Robohelp for Word" to generate a Webhelp
system. During the generation, Robohelp transforms Word documents into HTML
files. The problem is that the HTML code generated is unconventional, and we
need to provide a clean code to our clients. So I was asked to write a
search and replace macro that will scan more than 3000 files and make the
appropriate adjustments.
Problem:
Sometimes the search string reaches beyond the 255 characters limit and I am
not sure how to make it accept more. I read somewhere that I need to use the
"InStr" function, but I don't know how.
Thanks for any help.
Carlos
-------------- START OF CODE-----------------------
Sub FixHTMLCode()
' Macro created by Carlos Chalhoub
' This macro fixes HTML code in all files in a directory
Dim strFolderName As String
' Specify the location of the folder
strFolderName = BrowseFolder("Specify the path to the folder containing the
files.")
If Right(strFolderName, 1) <> "\" Then
strFolderName = strFolderName & "\"
End If
With Application.FileSearch
.FileName = "*.htm"
.LookIn = strFolderName
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
If .Execute <> 0 Then 'start search, and if any files found then
proceed...
For i = 1 To .FoundFiles.Count 'loop through all files in folder
Documents.Open FileName:=.FoundFiles(i), ConfirmConversions:=False,
Format:=wdOpenFormatText
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = _
"(\<P class=""List"" \>\<FONT style=""font-family:'Symbol';
font-size:10pt; "" \>·\</FONT\>\<span style=""font-size:8pt;
font-family='Times New Roman'; letter-spacing=0pt;
font-weight=normal;""\> \</sp
an\>)(*)(\</p\>)"
.Replacement.Text = _
"<ul { list-style: outside; margin-bottom:3.00pt }
.Forward = True<li>\2</li></ul>"
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.Close SaveChanges:=wdSaveChanges
Next i
Else: Exit Sub
MsgBox "There were no files found."
End If
End With
End Sub
-----------------------------END OF CODE-------------------------------