Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with macro from word97 to word2000

Status
Not open for further replies.

nesplb

Programmer
Jul 29, 2003
109
NO
Hi!
I hvae a marcro that finds heading 1 in a document and inserts a particular style on the line over the heading. This works ok in word97, vut in word2000 nothing happens...

example:
before the macro is run:

Heading1
some text (Normal)
some text (normal)

after the macro is run:

Style1
heading1
some text (Normal)
some text (Normal)

Can anyone help me to solve this problem?
Is there a tool for converting a '97 macro to a '2000 macro?

Here's the code:
Code:
 Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = "^c^&"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.TypeParagraph
    Selection.MoveUp Unit:=wdLine, Count:=1
    Selection.Style = ActiveDocument.Styles("Style1")
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Copy
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Heading 1")
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ""
        .Replacement.Text = "^c^&"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Thanx in advance!




Pål Nesteby

PDC-Tangen
Norway
 
Looking at your name and where you are, you seem to be using a foreign language version of Word. What are you replacing no text with in the 4th line? Try recording that step in Word 2000, as the short names in the find and replace window are now in English.

If this works, change the replace text in the lower part as well.

I know, because I am in Germany and had to change 5 million field names and so on when we switched from 97 to 2002.

Carol, Berlin :)
 
Thank you for the tip! I have now found the root of my problem...
But I haven't solved the problem yet...;)

I also wrote some error in my last post The first 13 lines is actually an error, the code starts at no. 14...Sorry. In this post I have provided the correct code so far.

When I say:
Code:
 selection.Copy [/code> in the code, shouldn't the content of the clipboard be "Style1"? -Or should I say something else for copying the style?

-the ^c and ^& in line 17 in the code is supposed to paste the content of the clipboard + the search text.(Heading 1)

-But in my macro the c^ doesn't paste "Style1" in word2000. In '97 it does. Is there a different letter for pasting styles perhaps?

[code]

 Selection.TypeParagraph
    Selection.MoveUp Unit:=wdLine, Count:=1
    Selection.Style = ActiveDocument.Styles("Style1")
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
'The next line is supposed to copy "Style1"
    Selection.Copy
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Heading 1")
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ""
'The next line is supposed to replace text with 
'"Style1"and the search text...
        .Replacement.Text = "^c^&"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

Paul



Pål Nesteby

PDC-Tangen
Norway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top