Opinion from Doug Robbins and Peter Hewett Requested

P

Peter Hewett

Hi Ann Scharpf

Greg's *always* very accommodating and always goes out of his way to help - as he's doing
now.

Enjoy the bounty of his labor + Cheers - Peter


Peter:

As I stated in my original post on the Word DOCUMENT
MANAGEMENT page, I don't know Visual Basic. So, I am
going to use whatever macro file Greg has finished and be
eternally grateful because it will be orders of magnitude
better than having our word processing team try to do
about 5,000 search & replace functions manually.

So, if there is no log file and I have the word processing
team run the replacement macros with Track Changes turned
on, do you think that will serve as an adequate log?

I really appreciate the input that all of you have made on
Greg's attempt to help me out!

Ann Scharpf
Systems Analyst/Help Developer
Planned Systems International

from "Class1" to "LogIt", then cut and
(called instantiation) so that you
Search and Replace procedure I use

HTH + Cheers - Peter
 
G

Greg Maxey

Peter,

I have managed to marry the two together. Unfortunately I can get no
further than generating a log file listing the name of each file that
searched and the attached template. I can see why the log is recording that
data, but I have no idea how to "output" any other data that the logit class
module might provide (e.g., what was changed, date, time, how many changes,
etc.) Am I talking apples and oranges here?

I have been using the F8 feature for quite sometime. The breakpoint
suggestion handing to see the start of the logit module, however, for some
reason this standard module goes into automode once the first file to be
searched is opened. After I step through to that first instance I can no
longer evaluate each step in the process. Hence I can see what information
the logit file might be storing as changes are being made in the searched
documents.

Thanks for your help.
 
P

Peter Hewett

Hi Greg Maxey

To get the Logit class timestamping each log message change the instantiation code from my
example from:

' Create a new logfile using the Folder and Name specified
Set mlogFile = New LogIt
mlogFile.Path = "f:\templates\test documents\"
mlogFile.File = "change log.txt"

to:
' Create a new logfile using the Folder and Name specified
Set mlogFile = New LogIt
mlogFile.Path = "f:\templates\test documents\"
mlogFile.File = "change log.txt"
mlogFile.TimeStamp = True

Post the code, but not the Logit Class code. I'm out tomorrow but I'll try to take a look
tomorrow night. By changing the Search/Replace code we can count and log the number of
changes of each replacement made as well.

HTH + Cheers - Peter
 
G

Greg Maxey

Peter,

Thanks and no hurry. After I moved the standard and class module to a new
template, I stetted out the lines below to close any open file.

Public Sub BatchFileMultiFindAndReplace()

'This macro is a collection of work by Doug Robbins, Peter Hewett, Klaus
Linke, Graham Mayor and Greg Maxey

Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim rngstory As Word.Range
Dim ListArray
Dim WordList As Document

' Create a new logfile using the Folder and Name specified
Set mlogFile = New LogIt
mlogFile.Path = "D:\My Documents\Word Documents\Word Tips\Macros"
mlogFile.File = "change log.txt"
mlogFile.TimeStamp = True

'Close any documents that may be open
'If Documents.Count > 0 Then
'Documents.Close SaveChanges:=wdPromptToSaveChanges
'End If
' Change the path and filename in the following to suit where you have your
list of words
Set WordList = Documents.Open(FileName:="D:\My Documents\Word Documents\Word
Tips\Find and Replace List.doc")
ListArray = WordList.Tables(1).Range.Text
ListArray = Split(ListArray, Chr(13) & Chr(7))
WordList.Close
' Get the folder containing the files
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With

If Left(PathToUse, 1) = Chr(34) Then
PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If

myFile = Dir$(PathToUse & "*.*")

While myFile <> ""
'Open each file and make the replacement
Set myDoc = Documents.Open(PathToUse & myFile)
'Fix the skipped blank Header/Footer problem
MakeHFValid
'Iterate through all story types in the current document
For Each rngstory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
SearchAndReplaceInStory rngstory, ListArray
' Get next linked story (if any)
Set rngstory = rngstory.NextStoryRange
Loop Until rngstory Is Nothing
Next

' Write something to the log file
mlogFile.Output "Current document: " & ActiveDocument.FullName
mlogFile.Output "Uses template: " & ActiveDocument.AttachedTemplate.FullName
'Close the file, saving the changes.
myDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend


End Sub
Public Sub SearchAndReplaceInStory(ByVal rngstory As Word.Range, ByRef
ListArray As Variant)
'This routine supplied by Peter Hewett and modified by Greg Maxey

Dim Source As Document
Dim i As Integer
Dim Find As Range
Dim Replace As Range
Set Source = ActiveDocument
Source.Activate
For i = LBound(ListArray) To UBound(ListArray) - 1 Step 3
With rngstory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ListArray(i)
.Replacement.Text = ListArray(i + 1)
..Wrap = wdFindContinue
..Format = False
..MatchCase = True
..MatchWholeWord = False
..MatchAllWordForms = False
..MatchSoundsLike = False
..MatchWildcards = False
..Execute Replace:=wdReplaceAll
End With
Next i
End Sub
Public Sub MakeHFValid()
'And this too
Dim lngJunk As Long
' It does not matter whether we access the Headers or Footers property.
' The critical part is accessing the stories range object
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
End Sub
 
G

Greg Maxey

Peter,

If you come back to this thread and don't see a reply from me it is because
I will be away for a bit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top