Legal Learning was telling us:
Legal Learning nous racontait que :
Hey Jean-Guy,
The reason why I did not use Klaus' code is because it keeps asking
me which macro to run and the macro that does the work does not
launch - I have to choose it from the macros dialog window. I don't
know enough on how to change that.
Does that make any sense?
I understand that it can be a bit overwhelming at first. The reason Klaus
presented that code was that each task was located in a separate sub, so
the whole things is organized and easily re-usable.
I guess Klaus' comments might have been a bit obscured to a beginner.
So, let's try again:
Klaus presented you with three Subs:
1) Private Sub LoopStoryRanges(myMacro As String)
2) Sub TestHeadersFooters()
3) Sub TestHeadersFootersRange(myRange As Range)
Any sub that has a parameter (The stuff between brackets - like (myMacro As
String) and so on) cannot be a starting point for a procedure. The parameter
means that the Sub needs that information before it can run. Sub 1) needs
the name of macro that it will in turn call from within its own code. This
name is provided by Sub 2) which calls Sub 1) (See the line "LoopStoryRanges
("TestHeadersFootersRange")" - this means that Sub 2) calls Sub 1)
[LoopStoryRanges] which will call Sub 3) [TestHeadersFootersRange]...)
The third Sub needs a range object, provided by Sub 1) ("Application.Run
myMacro, myStoryRange" - here myMacro, the name of the parameter, has the
value "TestHeadersFootersRange" because this is what the parameter received
from Sub 2) was when it called it).
So, all three together work like this (I am using my code which is based on
Klaus'):
You start with Sub 2)
All Sub 2) does is call Sub 1) giving Sub 1) the name of a macro to call
whenever it gets to that point in its code - in this case, the name of Sub
3).
Sub 1) does the job of looping through all the StoryRanges in the document
(Areas of text), and when it sets the next StoryRange it calls Sub 3)
through its parameter value.
Sub 3) tests if the StoryRange (which is a type of Range) is a footer, if
so, it tests for the presence of both Date and Time fields, if one of those
is missing, the code inside the "If lngFields = 0 Or lngFields = 1 Then"
block gets executed.
This why I said you need to add your stuff where it says 'Code Here.
I guess it would have been more linear if it had been presented thus:
1) Sub TestHeadersFooters()
2) Private Sub LoopStoryRanges(myMacro As String)
3) Sub TestHeadersFootersRange(myRange As Range)
Sorry about that.
I think you need to run other macros before and after the fields business
(the WORLDOX stuff), this is why in my previous messageI stated that you
need to use this:
'_______________________________________
Sub TestHeadersFooters()
Application.Run macroname:="WORLDOX.NewMacros.WdClearFooter"
LoopStoryRanges ("TestHeadersFootersRange")
Application.Run macroname:="WORLDOX.NewMacros.WdUpdateFooter"
End Sub
'_______________________________________
instead of
'_______________________________________
Sub TestHeadersFooters()
LoopStoryRanges ("TestHeadersFootersRange")
End Sub
'_______________________________________
As you can see, once you understand hw it all works, you can easily recycle
those Subs. If you want to call a different macro when each StoryRange is
found, change
LoopStoryRanges ("TestHeadersFootersRange")
to something like
LoopStoryRanges ("NameOfOtherMacro")
Or, you could change
Select Case myRange.StoryType
Case wdEvenPagesFooterStory, wdFirstPageFooterStory, _
wdPrimaryFooterStory
so that you have a totally different action whether the actual StoryRange is
a primary footer or not, whether it is a textbox or a footnote, etc.
Good luck.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org