Hello Doug,
Since it was your "loop through all ranges" code that made it possible to
write this macro in the first place, I'm very grateful for your help. Here
are more details, and the full current version of the macro is here (remove
the .txt extension to create an importable module, of course):
http://www.columbia.edu/~em36/WPSymbolConverter0999.bas.txt
You'll find your name in the comments at the top.
This is a gigantic kludge of a macro that is designed to replace the
invisible and unsearchable fields that Word 2002/2003 uses when importing WP
files that contain typographic symbols, etc, *and* when the WP
TypographicSymbol and other WP fonts are present on the system.
The macro uses vast amounts of code to work around what seems to be a bug in
Word, in which the name of the font in the InsertSymbol dialog isn't
accessible in VBA (although the character number is easily available). The
macro builds upon this block of code by Helmut Weber:
Sub GetTypographicSymbol()
Dim rDcm As Range
Dim oChr As Object
Dim sFnt As String
Set rDcm = ActiveDocument.Range
For Each oChr In rDcm.Characters
If Asc(oChr) = 40 Then ' applies to most (or all) decorative fonts?
oChr.Select
sFnt = Dialogs(wdDialogInsertSymbol).Font ' that's it!
if sFnt = "WP TypographicSymbol then ' can't test it
' whatever ,exit or wpfound = true etc.
endif
End If
Next
End Sub
As the comment says, you can't test for Dialogs(wdDialigInsertSymbol).Font,
so this macro displays the dialog and uses SendKeys to get the font name
into the clipboard. It's really, really ugly, but it works.
The trouble is that the Asc(oChr) = 40 test causes the macro to stop at
every open-parenthesis character (ascii 40) in addition to every decorative
font. This slows things down in documents with hundreds of parentheses (e.g.
many legal and scholarly documents), so I got the idea of replacing all the
open parens with a high unicode character at the start, then running the
humongous code in the middle, and then restoring the open parens at the end.
It's all there in the code, but in a very primitive state, as there are no
tests for whether or not to perform the replace-restore parens routines -
just the brute force actions themselves.
I'm a beginner at VBA, so please forgive any obvious sillinesses in the
code. Helmut Weber has helped me get rid of a lot of stupidities, but there
are probably plenty left over.
Thanks again,
Edward Mendelson
Doug Robbins said:
Without knowing what the "real work of the macro" is, it is difficult to
tell you what is really the best way to do it, but I would be pretty
certain that to use a Do While >Execute( ) = True...Loop construction as
in the following will almost certainly be the way to go. Then (a) there
is no need to replace the open parens and later replace them and nothing
at all happens if no open parens are found.
' Macro to round all numbers in a document
' Macro created 19/7/00 by Doug Robbins
'
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{1,}.[0-9]{3,}", MatchWildcards: =
True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Range.Text = Round(Selection.Range.Text, 2)
Loop
End With
--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a
paid consulting basis.
Hope this helps,
Doug Robbins - Word MVP
Edward Mendelson said:
I thought the answer to this would be obvious, but I can't manage to find
it
after a lot of searching.
In a Word macro, I want to (1) temporarily replace all instances of the
open-parenthesis character with another character; then (2) perform the
real
work of the macro; and then (3) reverse the original replacement of the
open-parenthesis character so that the parentheses are back where they
should be.
For efficiency, I would like to know whether or not step (1) actually
found
any open-parentheses to replace; if none were found, then I would want to
skip step (3).
Because this macro would search for all open parentheses in all story
ranges, following the method shown here -
http://word.mvps.org/FAQs/Customization/ReplaceAnywhere.htm
- I think I would save time in complex documents by *not* performing step
(3) if it isn't needed because nothing got replaced in step (1).
Or would it be simpler to test simply whether an open-parenthesis
character
exists in the document, and then make the replacement if it does? What
would
be the most efficient way to manage that one?
Many thanks for any help...
Edward Mendelson