Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Word 2002 macro problem (finding styles)


  • Please log in to reply

#1
delfin

delfin

    New Member

  • Member
  • Pip
  • 2 posts
I'm attempting to set up a new Word template, including functions that will convert content from my group's previous template. I'm working in Word 2000, but the code will need to work across versions (Word 2002, possibly 97 and XP as well).

Most of my macros revolve around finding particular styles in the document, moving the insertion point to that location and performing actions. I've got the majority of them working just how I want them to work in Word 2000, and all seemed well. Yesterday, I had someone test the template in Word 2002 and several of the macros failed there.

I'd used Record A Macro to record the functions in 2000, so I figured that doing that in 2002 would produce compatible macros for 2002. No dice -- it produced the EXACT SAME CODE. The steps being performed worked fine as they were being recorded in both 2000 and 2002, and in macro form in 2000, but won't work as a macro in 2002.

I narrowed the problem as follows in 2002:
* Typed the word "plotz" in a document. Recorded a macro that would use a CTRL-F Find to find the word "plotz". Ran the macro, success.

* Put the word "plotz" in a table, repeated the above, success, so it's not a table issue.

* Changed the style of the word "plotz" to Heading 6 (a style I don't normally use), hit Record, did a CTRL-F search for "plotz", ran the macro. Success, so searches for specific text are fine.

* Hit Record, did a CTRL-F search for Heading 6 style (no text specified), success. When I ran the macro, however, it failed to find Heading 6 anywhere in the document, and coughed and died when it reached the action following the search.

Sample recorded macro:
Sub FindContinued()
'
' FindContinued Macro
' Macro recorded 6/23/2005 by delfin
'
'  Find the Continued Topic style in the document

    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Continued Topic")
    Selection.Find.ParagraphFormat.Borders.Shadow = False
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute

' Deselect what is found, and put cursor at beginning of that line

    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.HomeKey Unit:=wdLine
End Sub

I have a number of macros that use similar Selection.Find.Style functionality, and they're all failing in 2002. I am at a loss as to what to look for in 2002, and have limited testing time in that environment (I'd be taking work time away from coworkers' machines). Thoughts?
  • 0

Advertisements


#2
cyntekllc

cyntekllc

    New Member

  • Member
  • Pip
  • 1 posts
You need to enter a search string in your macro:

With Selection.Find
.Text = "" ----->search string needs to go here
.Replacement.Text = "" ----->replacement string needs to go here
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP