Re: Opinion from Doug Robbins and Peter Hewett Requested
From: Greg Maxey (gmaxey_at_whamspammvps.org)
Date: 06/19/04
- Next message: Chris Joyce: "Re: Find any Arial and replace it with Times New Roman"
- Previous message: Chris Joyce: "Re: Find any Arial and replace it with Times New Roman"
- In reply to: Peter Hewett: "Re: Opinion from Doug Robbins and Peter Hewett Requested"
- Next in thread: Peter Hewett: "Re: Opinion from Doug Robbins and Peter Hewett Requested"
- Reply: Peter Hewett: "Re: Opinion from Doug Robbins and Peter Hewett Requested"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 19 Jun 2004 14:22:45 GMT
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.
-- Greg Maxey A peer in "peer to peer" support Rockledge, FL To e-mail, edit out the "w...spam" in gmaxey@whamspammvps.org Peter Hewett wrote: > Hi Greg > > If you're not sure what going on create a new Template/Project and > add the Class Module code and the standard module code. Set a > breakpoint at the statement "Set mlogFile = New LogIt" and single > step through the code using F8. This is a *really* good way of > getting to grips with what's going on (and it isn't as bad as you > might think). Once you're comfortable with what the codes doing > integrate it into the larger project. This is generally the way all > larger pieces of code are built up. It much easier to abstract and > test the functionality of code (where possible) outside of a heap of > other code, it allows you to focus on just the one thing. > > HTH + Cheers - Peter > > > "Greg" <anonymous@discussions.microsoft.com>, said: > >> Peter, >> >> <<I think you get the idea. >> >> You assume too much. I don't get the idea. I managed to >> create the class module well enough but when you shifted >> to generalizations the fog rolled in: >> >> <<Now you then need to create an instance of your class >> (called instantiation) so that you can use the class. Add >> this code to a standard Module: >> >> What Standard Module? Do you mean the same module that >> has the find and replace macro? >> >> Private mlogFile As LogIt >> >> Public Sub DoSomething() >> >> ' Create a new logfile using the Folder and Name cified >> Set mlogFile = New LogIt >> mlogFile.Path = "f:\templates\test documents\" >> mlogFile.File = "change log.txt" >> >> ' Write something to the log file >> mlogFile.Output "Current document: " & >> ActiveDocument.FullName >> mlogFile.Output "Uses template: " & >> ActiveDocument.AttachedTemplate.FullName >> End Sub >> >> >> >> >> >> >> >>> -----Original Message----- >>> Hi Greg Maxey >>> >>> The log file actually dead easy. Add a class module to >> your project and using the >>> Property window in the VBA IDE change its name >> from "Class1" to "LogIt", then cut and >>> paste the following code into the Logit Class: >>> >>> <===========Start of Class Module LogIt================> >>> Option Explicit >>> >>> Private mstrFile As String >>> Private mstrPath As String >>> Private mboolEnabled As Boolean >>> Private mboolTimeStamp As Boolean >>> >>> Public Sub Output(ByVal strText As String) >>> Const cProcedureName As String = "Log::Output" >>> >>> Dim hFile As Long >>> >>> On Error GoTo OutputError >>> >>> ' Everything must be right for us to log the passed >> text >>> If CanOutput Then >>> >>> ' Prefix log text with timestamp >>> If TimeStamp Then strText = Now & vbTab & strText >>> >>> ' Open log file for append >>> hFile = FreeFile >>> Open mstrPath & mstrFile For Append Access Write >> As hFile >>> >>> ' Write the output and tidy up >>> Print #hFile, strText >>> Close hFile >>> End If >>> >>> OutputExit: >>> Exit Sub >>> >>> OutputError: >>> mboolEnabled = False >>> Err.Raise Err.Number, cProcedureName, Err.Description >>> End Sub ' Output >>> >>> Public Sub Kill() >>> On Error GoTo HandleError >>> >>> ' Delete the current log file if it exists >>> If Len(Dir$(mstrPath & mstrFile)) > 0 Then >>> Kill mstrPath & mstrFile >>> End If >>> >>> ExitHere: >>> Exit Sub >>> >>> HandleError: >>> mboolEnabled = False >>> Err.Raise vbObjectError + 8001, "Log::Kill", _ >>> Err.Description >>> Resume ExitHere >>> End Sub ' Reset >>> >>> Public Property Get Path() As String >>> Path = mstrPath >>> End Property >>> Public Property Let Path(ByVal strPath As String) >>> strPath = Trim$(strPath) >>> If Right$(strPath, 1) <> "\" Then strPath = strPath >> & "\" >>> mstrPath = Trim$(strPath) >>> End Property >>> >>> Public Property Get File() As String >>> File = mstrFile >>> End Property >>> Public Property Let File(ByVal FileName As String) >>> mstrFile = FileName >>> End Property >>> >>> Public Property Get Enabled() As Boolean >>> Enabled = mboolEnabled >>> End Property >>> Public Property Let Enabled(ByVal EnableLogFile As >> Boolean) >>> mboolEnabled = EnableLogFile >>> End Property >>> >>> Public Property Get TimeStamp() As Boolean >>> TimeStamp = mboolTimeStamp >>> End Property >>> Public Property Let TimeStamp(ByVal TimeStampOutput As >> Boolean) >>> mboolTimeStamp = TimeStampOutput >>> End Property >>> >>> Public Property Get CanOutput() As Boolean >>> CanOutput = LenB(Path) > 0 And LenB(File) > 0 And >> Enabled >>> End Property >>> >>> Private Sub Class_Initialize() >>> Me.Enabled = True >>> End Sub >>> <============End of Class Module LogIt================> >>> >>> Now you then need to create an instance of your class >> (called instantiation) so that you >>> can use the class. Add this code to a standard Module: >>> >>> Private mlogFile As LogIt >>> >>> Public Sub DoSomething() >>> >>> ' 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" >>> >>> ' Write something to the log file >>> mlogFile.Output "Current document: " & >> ActiveDocument.FullName >>> mlogFile.Output "Uses template: " & >> ActiveDocument.AttachedTemplate.FullName >>> End Sub >>> >>> I think you get the idea. Rather than use a standard >> Search and Replace procedure I use >>> one with a counter, that counts the number of changes >> made. This of course makes it >>> slower but does enable a comprehensive log to be produced. >>> >>> Cheers - Peter >>> >>> "Greg Maxey" <gmaxey@whamspammvps.org>, said: >>> >>>> Peter, >>>> >>>> You along with Doug and Klaus are in the big league >> while I play in the sand >>>> lot (or worse yet, sand box). I sometimes manage to >> combine and copy >>>> existing code that you fellows provide or add a bell and >> whistle here in >>>> there but I haven't a clue how to do from scratch any of >> the the processes >>>> you mention (except of couse make small batches). >>>> >>>> I will certainly have a look at the post you sent Ann as >> it was here >>>> question that got me interested to begin with. >>>> >>>> With another follow up by Klaus I managed to get the >> code with the array >>>> working. Since it works I will leave well enough >> alone ;-) >>>> >>>> Perhaps I will bug you guys in the future for small >> hints how to start and >>>> stop Word between operations and how to create the log >> file. >>>> >>>> The "slowes" is an annoyance. I played around with a >> vbMsgbox result and IF >>>> statement in an attempt to do a quick search just on the >> Main Text. >>>> Something like "Do you want to replace in the main text >> only?" IF vbResult >>>> is vbYes Then Set rngstory = wdMainTextStory... >>>> >>>> Alas no joy. >>>> >>>> Thanks Peter, you are always a great help >>> >>> HTH + Cheers - Peter >>> >>> .
- Next message: Chris Joyce: "Re: Find any Arial and replace it with Times New Roman"
- Previous message: Chris Joyce: "Re: Find any Arial and replace it with Times New Roman"
- In reply to: Peter Hewett: "Re: Opinion from Doug Robbins and Peter Hewett Requested"
- Next in thread: Peter Hewett: "Re: Opinion from Doug Robbins and Peter Hewett Requested"
- Reply: Peter Hewett: "Re: Opinion from Doug Robbins and Peter Hewett Requested"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|