The Cellar  

Go Back   The Cellar > Main > Technology
FAQ Community Calendar Today's Posts Search

Technology Computing, programming, science, electronics, telecommunications, etc.

Reply
 
Thread Tools Display Modes
Old 06-23-2005, 02:52 PM   #1
vsp
Syndrome of a Down
 
Join Date: Jun 2001
Location: West Chester
Posts: 1,367
That helped quite a bit.

Next puzzler: What built-in routine can I use to check for the existence of a particular style in a document? STYLEREF works great for grabbing the previous reference of a particular style, but I'm looking for a Boolean here.

Pseudocode I want to use goes something like this:

IF (Style X exists)
THEN
{
(move to next instance of Style X)
(perform action, replacing Style X with my new structure)
}
ENDIF

Or

WHILE (Style X exists)
{
(move to next instance of Style X)
(perform action, replacing Style X with my new structure)
}

...needing it to bail out if the style is no longer present.

Word's Find/Replace functionality doesn't seem to want to bail out when in macro form. If I have something like:

{
FIND (Style X)
(Hit Delete key)
}

bound together, it works great as long as Style X exists. If it doesn't, it ignores the first line and simply executes whatever's in the rest of the routine, instead of kicking out a "Selection not found" error like it would if I searched for it manually.

Suggestions?
vsp is offline   Reply With Quote
Old 06-29-2005, 08:46 AM   #2
vsp
Syndrome of a Down
 
Join Date: Jun 2001
Location: West Chester
Posts: 1,367
I have everything I need working pretty well in Word 2000, functioning properly almost 100% of the time with proper input.

Naturally, someone tested my code in Word 2002 today, and it fails completely. Bafflingly, Word 2002 seems unable to handle basic Find/Replace functionality that I recorded using Record A Macro in Word 2000.

Here's a sample chunk of code that's failing:
Code:
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Block Label")
    Selection.Find.ParagraphFormat.Borders.Shadow = False
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = False
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    Do While .Execute
      (Text manipulation goes here)
    
' End and repeat the loop until all Units in the doc are done
   Loop
   End With
   Selection.EndKey Unit:=wdStory
This is NOT complicated stuff. Move up in the document, find Block Label style, twiddle it, then find the next place it appears and repeat the process.

In Word 2002, the Find _fails_. I've checked the styles on the structures, and they're perfect. I click the icon for my macro and it scans through the document, doesn't find _any_ instances of Block Label <b>even though I can SEE several of them on any given page</b>, and coughs and dies.

Is there something about using Find to find text in tables in Word 2002 that I really need to know?

(For reference, it's not the loop that's failing. The debugger is pointing to the Find statement itself and returning a "Not found in document" error, and my versions that do them one at a time without looping fail the same way.)
vsp is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 07:39 PM.


Powered by: vBulletin Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.