-
-
Jan,
As best I can tell you first macro does convert numbers to text in all the storyranges. What problem are you experiencing?
-
Hello Greg,
Thanks for responding.
The problem I’m experiencing is my own understanding of how one line: “ConvertNumbersToText” -- passes through all the story layers?
Is it because it is a VBA “method” – and therefore works upon the entire document?
I thought this needed to pass through all story layers, and thus the second macro was my attempt at making sure all story layers were accessed – but this second macro runs VERY SLOW.
Can I simply rely on the first macro to access all document stories?
Thanking you,
Janet
"If" is a big word.
-
I started to have a big long response explaining the concept of story ranges... and then I looked at the help file on the ConvertNumbersToText Method.
It operates on the document object. Since it operates on the document object (and not a Range object), yes... for better or worse, you can run your first macro... and the only thing your second macro is doing it simply running the first macro as many times as you have paragraphs in all of the various story ranges in your document (which can be a pretty big number, depending on how complicated your document is).
That's why the second one is slow. You're probably running the exact same line of code a bunch of times, instead of just once.
i.e., the following code would be slow too...
[vba]
For i = 1 to 1500
ActiveDocument.ConvertNumbersToText
Next
[/vba]
-
-
Jan,
I replied "as best I could tell" because like Jason I was preparing to offer an explaination of processing storyranges (probably not as big or as long) when it dawned on me that being a document method, ConvertNumbersToText did act on the entire document and not just a range. I was convinced when I embedded a numbered list in the text frame of a shape object in the header of a document. That is one place in a document that even procecssing storyranges won't get to unless you dig a little deeper as the following may illustrate. Add a shape the header of a document and then add a REF field to the shape, to the header, and in the document. Run this code with the Select Case statement stetted out as shown. You will see that the REF fields in the document and in the header will update. Unstet the Select Case statement and run the code again. All fields will update.
[VBA]Sub myUpdateFields()
Dim rngStory As Word.Range
Dim oShp As Word.Shape
For Each rngStory In ActiveDocument.StoryRanges
Do
On Error Resume Next
rngStory.Fields.Update
'Select Case rngStory.StoryType
'Case 6, 7, 8, 9, 10, 11
'If rngStory.ShapeRange.Count > 0 Then
'For Each oShp In rngStory.ShapeRange
'If oShp.TextFrame.HasText Then
'oShp.TextFrame.TextRange.Fields.Update
'End If
'Next oShp
'End If
'Case Else
'Do Nothing
'End Select
On Error GoTo 0
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next rngStory
End Sub
[/VBA]
-
-
You're welcome and yes it is a great time to be associated in any manner with the United States Navy SEALS.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules