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-17-2005, 11:41 AM   #1
vsp
Syndrome of a Down
 
Join Date: Jun 2001
Location: West Chester
Posts: 1,367
Word 2000 stunt driving me nuts

Any Word or WordBasic gurus out there? I've got an issue that's driving me batty.

My document has a table at the top of each page, containing a handful of cells with specific text styles. I've got a macro worked out that allows me to clone a previous page's header table structure:

1) Page break from insertion point
2) Insert a temporary bookmark to mark my place
3) Search up for a particular style, which appears only in my header tables
4) Select and copy the table
5) Jump to the bookmark
6) Paste the table on the new page
7) Tweak one of the text styles in one block, to avoid a minor TOC issue
8) Delete the temporary bookmark.

Easy enough. However, here's what I _really_ want a secondary macro to do:
9) Do 1 through 8 to set up a new page.
10) Set up a bookmark at the page title position.
11) Change the style for that position from Page Title to Page Title Continued (same formatting, just making a style distinction).
12) Search up for the closest Page Title text and copy it.
13) Create a FIELD at the insertion position containing the previous Page Title text.
14) Throw ", page continued" after it on the new page.

So that I end up with something like:

Page 1: Title blah blah.
Page 2: [Title blah blah], page continued.
Page 3: [Title blah blah], page continued.
Page 4: A new title.
Page 5: [A new title], continued.

where I can update Page 1, 4, etc. and refresh the document to autoupdate the dependent fields.

The stopper is Step 13. Anyone got a hint as to how I'd manage that?
vsp is offline   Reply With Quote
Old 06-17-2005, 11:55 AM   #2
Happy Monkey
I think this line's mostly filler.
 
Join Date: Jan 2003
Location: DC
Posts: 13,575
Have you tried the "STYLEREF" field code?
__________________
_________________
|...............| We live in the nick of times.
| Len 17, Wid 3 |
|_______________| [pics]
Happy Monkey is offline   Reply With Quote
Old 06-23-2005, 02:52 PM   #3
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   #4
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
Old 06-29-2005, 10:44 AM   #5
vsp
Syndrome of a Down
 
Join Date: Jun 2001
Location: West Chester
Posts: 1,367
Narrowed down the problem by testing in Word 2002.

I type the word "Potrzebie" in a document somewhere. If I do the following:
* Turn on Record A Macro, hit CTRL-F to call up Find, and search for the text string Potrzebie

it works, both while recording and as a macro.

I change Potrzebie to Heading 6 style. If I do the following:
* Turn on Record A Macro, hit CTRL-F to call up Find, and search for the text string Potrzebie

it works, both while recording and as a macro.

But if I:
* Turn on Record A Macro, hit CTRL-F to call up Find, and search for the text style Heading 6,

it works when I'm recording but DOES NOT WORK as a macro.

This:
Code:
Selection.Find.Style = ActiveDocument.Styles("style name here")
is generated by Word 2002's own Record a Macro code but does not appear to work in Word 2002.

Thoughts? Workarounds? Icepicks to my skull?
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 06:12 PM.


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