My Word 97 macros don't run in Word 2000 
Author Message
 My Word 97 macros don't run in Word 2000

Some of the macros that I created in Word 97 do not run in
Word 2000. A dialog box comes up saying: "Compile error:
Invalid character." What is wrong?


Wed, 05 May 2004 11:24:53 GMT  
 My Word 97 macros don't run in Word 2000
Hi Bp,

Quote:
> Some of the macros that I created in Word 97 do not run in
> Word 2000. A dialog box comes up saying: "Compile error:
> Invalid character." What is wrong?

Impossible to say without seeing the macro code (copied into
a message of course - no attachments, please!)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)



Wed, 05 May 2004 18:58:50 GMT  
 My Word 97 macros don't run in Word 2000

Quote:
>-----Original Message-----
>Hi Bp,

>> Some of the macros that I created in Word 97 do not run
in
>> Word 2000. A dialog box comes up saying: "Compile
error:
>> Invalid character." What is wrong?

>Impossible to say without seeing the macro code (copied
into
>a message of course - no attachments, please!)

>Cindy Meister
>INTER-Solutions, Switzerland
>http://homepage.swissonline.ch/cindymeister
>http://www.mvps.org/word
>http://go.compuserve.com/MSOfficeForum

>This reply is posted in the Newsgroup; please post any
follow
>question or reply in the newsgroup and not by e-mail :-)

>Thanks for responding, Cindy. Below is the code:

Sub prepare()
'
' This macro:
'   1.  Removes deletable styles
'   2.  Attaches formatter and updates styles
'   3.  Changes all paragraphs to Body Text
'   4.  Removes the first line indent in Body Text
'   5.  Replaces two consecutive paragraph marks with one
'   6.  Changes all text in all paragraphs to 11 point
'   7.  Replaces two consecutive spaces with one
'   8.  Replaces remaining white space (i.e., two or more
'       consecutive spaces or tabs) with one space
'   9.  Removes space before a paragraph mark
'   10. Removes unneeded space (spaces) in tables
'   11. Replaces regular hyphens with nonbreaking hyphens
'   12. Changes underlining to italics
'   13. Changes all bolded text to regular text
'   14. Removes hyphen in "non-"
'   15. Removes hyphen in "pre-"
'   16. Removes hyphen in "post-"
'   17. Changes "low level" to "low-level"
'   18. Sets up page margins, size, and layout
'   19. Hides spelling errors

' Macro recorded 11/12/98
'
'1. Removes deletable styles

For Each Style In ActiveDocument.Styles
    Response = MsgBox("Do you want to delete the " & Style
& _
        " Style?", vbYesNoCancel)
    If Response = vbYes Then
         On Error Resume Next
         Application.OrganizerDelete
Source:=ActiveDocument.Name, _
             Name:=Style, Object:=wdOrganizerObjectStyles
    ElseIf Response = vbCancel Then
        Exit For
    End If
Next Style

For Each sty In ActiveDocument.Styles
    If sty.InUse = True Then sty.Delete
    On Error Resume Next
Next sty

'2. Attaches formatter and updates styles
With ActiveDocument
    .UpdateStylesOnOpen = True
    .AttachedTemplate = "C:\templates\formatter.dot"
    .UpdateStylesOnOpen = False
End With

'3. Changes all paragraphs to Body Text
Selection.WholeStory
Selection.Style = ActiveDocument.Styles("Body Text")
Selection.MoveUp Unit:=wdLine, Count:=1

'4. Removes the first line indent in Body Text
With ActiveDocument.Styles("Body Text").ParagraphFormat
    .FirstLineIndent = InchesToPoints(0)
End With

'5. Replaces two consecutive paragraph marks with one
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p"
    End With
Selection.Find.Execute Replace:=wdReplaceAll

'6. Changes all text in all paragraphs to 11 point
Selection.WholeStory
Selection.Font.Size = 11
Selection.MoveUp Unit:=wdLine, Count:=1

'7. Replaces two consecutive spaces with one
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "  "
        .Replacement.Text = " "
    End With
Selection.Find.Execute Replace:=wdReplaceAll

'8. Replaces remaining white space (i.e., two or more
'   consecutive spaces or tabs) with one space
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^w"
        .Replacement.Text = " "
    End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
    End With
Selection.Find.Execute

'9. Removes space before a paragraph mark
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = " ^p"
        .Replacement.Text = "^p"
    End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
    End With
Selection.Find.Execute

'10. Removes unneeded space (spaces) in tables
Selection.HomeKey Unit:=wdStory
front10:

Selection.GoTo What:=wdGoToTable
    If Selection.Information(wdWithInTable) = False Then
        GoTo finish10
    End If

top10:

Selection.Find.ClearFormatting
With Selection.Find
    .Text = " "
    .Replacement.Text = ""
End With
Selection.Find.Execute
    If Selection.Find.Found = False Then GoTo finish10
    If Selection.Information(wdWithInTable) = False Then
        GoTo front10
    End If

above10:

Selection.Previous(Unit:=wdCharacter, Count:=1).Select
If Selection.Type = wdSelectionColumn Then GoTo down10
Selection.Collapse Direction:=wdCollapseEnd
Selection.Find.ClearFormatting
With Selection.Find
    .Text = " "
    .Replacement.Text = ""
End With
Selection.Find.Execute
Selection.Next(Unit:=wdCharacter, Count:=1).Select
If Selection.Type = wdSelectionColumn Then GoTo down10
Selection.Collapse Direction:=wdCollapseEnd

GoTo top10

down10:

Selection.Collapse Direction:=wdCollapseEnd
If Selection.Type <> wdSelectionNormal Then _
Selection.MoveLeft Unit:=wdCharacter, Count:=2
If Selection.Text <> " " Then _
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.Delete

Selection.Find.ClearFormatting
With Selection.Find
    .Text = " "
    .Replacement.Text = ""
End With
Selection.Find.Execute

If Selection.Information(wdWithInTable) = False Then GoTo
front10

GoTo above10

finish10:

'11. Replaces regular hyphens with nonbreaking hyphens
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "-"
        .Replacement.Text = "^~"
    End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
    End With
Selection.Find.Execute

'12. Changes underlining to italics
Selection.Find.ClearFormatting
Selection.Find.Font.Underline = wdUnderlineSingle
Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Italic = True
        .Underline = wdUnderlineNone
    End With
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
    End With
Selection.Find.Execute Replace:=wdReplaceAll

'13. Changes all bolded text to regular text
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
Selection.Find.Replacement.ClearFormatting
    With Selection.Find.Replacement.Font
        .Bold = False
        .Italic = False
    End With
Selection.Find.Execute Replace:=wdReplaceAll

'14. Removes hyphen in "non-"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "non^~"
        .Replacement.Text = "non"
    End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
    End With
Selection.Find.Execute

'15. Removes hyphen in "pre-"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "pre^~"
        .Replacement.Text = "pre"
    End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
    End With
Selection.Find.Execute

'16. Removes hyphen in "post-"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "post^~"
        .Replacement.Text = "post"
    End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
    End With
Selection.Find.Execute

'17. Changes "low level" to "low-level"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "low level"
        .Replacement.Text = "low^~level"
    End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ""
    End With
Selection.Find.Execute

'   18. Sets up page margins, size, and layout
With ActiveDocument.PageSetup
    .LineNumbering.Active = False
    .Orientation = wdOrientPortrait
    .TopMargin = InchesToPoints(1)
    .BottomMargin = InchesToPoints(1)
    .LeftMargin = InchesToPoints(1)
    .RightMargin = InchesToPoints(1)
    .Gutter = InchesToPoints(0)
    .HeaderDistance = InchesToPoints(0.5)
    .FooterDistance = InchesToPoints(0.5)
    .PageWidth = InchesToPoints(8.5)
    .PageHeight = InchesToPoints(11)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    .SectionStart = wdSectionNewPage
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop
    .SuppressEndnotes = False
    .MirrorMargins = False
End With

'   19. Hides spelling errors
ActiveDocument.ShowSpellingErrors = False

End Sub

.

- Show quoted text -



Sat, 08 May 2004 10:21:15 GMT  
 My Word 97 macros don't run in Word 2000
The first thing to do is to separate these 19 sections into 19 macros
and run each one to pinpoint the line that trips it up.  (Ordinarily
the compiler would show you the code that's causing the problem when
it stops -- is it not doing this?)


-- See the MVP FAQ at http://www.mvps.org/word ---------------------
------------ "Life is nothing if you're not obsessed." --John Waters
--------------------------------------------------------------------
Please reply only to the newsgroup.

Quote:

> >-----Original Message-----
> >Hi Bp,

> >> Some of the macros that I created in Word 97 do not run
> in
> >> Word 2000. A dialog box comes up saying: "Compile
> error:
> >> Invalid character." What is wrong?

> >Impossible to say without seeing the macro code (copied
> into
> >a message of course - no attachments, please!)

> >Cindy Meister
> >INTER-Solutions, Switzerland
> >http://homepage.swissonline.ch/cindymeister
> >http://www.mvps.org/word
> >http://go.compuserve.com/MSOfficeForum

> >This reply is posted in the Newsgroup; please post any
> follow
> >question or reply in the newsgroup and not by e-mail :-)

> >Thanks for responding, Cindy. Below is the code:

> Sub prepare()
> '
> ' This macro:
> '   1.  Removes deletable styles
> '   2.  Attaches formatter and updates styles
> '   3.  Changes all paragraphs to Body Text
> '   4.  Removes the first line indent in Body Text
> '   5.  Replaces two consecutive paragraph marks with one
> '   6.  Changes all text in all paragraphs to 11 point
> '   7.  Replaces two consecutive spaces with one
> '   8.  Replaces remaining white space (i.e., two or more
> '       consecutive spaces or tabs) with one space
> '   9.  Removes space before a paragraph mark
> '   10. Removes unneeded space (spaces) in tables
> '   11. Replaces regular hyphens with nonbreaking hyphens
> '   12. Changes underlining to italics
> '   13. Changes all bolded text to regular text
> '   14. Removes hyphen in "non-"
> '   15. Removes hyphen in "pre-"
> '   16. Removes hyphen in "post-"
> '   17. Changes "low level" to "low-level"
> '   18. Sets up page margins, size, and layout
> '   19. Hides spelling errors

> ' Macro recorded 11/12/98
> '
> '1. Removes deletable styles

> For Each Style In ActiveDocument.Styles
>     Response = MsgBox("Do you want to delete the " & Style
> & _
>         " Style?", vbYesNoCancel)
>     If Response = vbYes Then
>          On Error Resume Next
>          Application.OrganizerDelete
> Source:=ActiveDocument.Name, _
>              Name:=Style, Object:=wdOrganizerObjectStyles
>     ElseIf Response = vbCancel Then
>         Exit For
>     End If
> Next Style

> For Each sty In ActiveDocument.Styles
>     If sty.InUse = True Then sty.Delete
>     On Error Resume Next
> Next sty

> '2. Attaches formatter and updates styles
> With ActiveDocument
>     .UpdateStylesOnOpen = True
>     .AttachedTemplate = "C:\templates\formatter.dot"
>     .UpdateStylesOnOpen = False
> End With

> '3. Changes all paragraphs to Body Text
> Selection.WholeStory
> Selection.Style = ActiveDocument.Styles("Body Text")
> Selection.MoveUp Unit:=wdLine, Count:=1

> '4. Removes the first line indent in Body Text
> With ActiveDocument.Styles("Body Text").ParagraphFormat
>     .FirstLineIndent = InchesToPoints(0)
> End With

> '5. Replaces two consecutive paragraph marks with one
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = "^p^p"
>         .Replacement.Text = "^p"
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll

> '6. Changes all text in all paragraphs to 11 point
> Selection.WholeStory
> Selection.Font.Size = 11
> Selection.MoveUp Unit:=wdLine, Count:=1

> '7. Replaces two consecutive spaces with one
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = "  "
>         .Replacement.Text = " "
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll

> '8. Replaces remaining white space (i.e., two or more
> '   consecutive spaces or tabs) with one space
> Selection.HomeKey Unit:=wdStory
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = "^w"
>         .Replacement.Text = " "
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
>     With Selection.Find
>         .Text = ""
>     End With
> Selection.Find.Execute

> '9. Removes space before a paragraph mark
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = " ^p"
>         .Replacement.Text = "^p"
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
>     With Selection.Find
>         .Text = ""
>     End With
> Selection.Find.Execute

> '10. Removes unneeded space (spaces) in tables
> Selection.HomeKey Unit:=wdStory
> front10:

> Selection.GoTo What:=wdGoToTable
>     If Selection.Information(wdWithInTable) = False Then
>         GoTo finish10
>     End If

> top10:

> Selection.Find.ClearFormatting
> With Selection.Find
>     .Text = " "
>     .Replacement.Text = ""
> End With
> Selection.Find.Execute
>     If Selection.Find.Found = False Then GoTo finish10
>     If Selection.Information(wdWithInTable) = False Then
>         GoTo front10
>     End If

> above10:

> Selection.Previous(Unit:=wdCharacter, Count:=1).Select
> If Selection.Type = wdSelectionColumn Then GoTo down10
> Selection.Collapse Direction:=wdCollapseEnd
> Selection.Find.ClearFormatting
> With Selection.Find
>     .Text = " "
>     .Replacement.Text = ""
> End With
> Selection.Find.Execute
> Selection.Next(Unit:=wdCharacter, Count:=1).Select
> If Selection.Type = wdSelectionColumn Then GoTo down10
> Selection.Collapse Direction:=wdCollapseEnd

> GoTo top10

> down10:

> Selection.Collapse Direction:=wdCollapseEnd
> If Selection.Type <> wdSelectionNormal Then _
> Selection.MoveLeft Unit:=wdCharacter, Count:=2
> If Selection.Text <> " " Then _
> Selection.MoveRight Unit:=wdCharacter, Count:=2
> Selection.Delete

> Selection.Find.ClearFormatting
> With Selection.Find
>     .Text = " "
>     .Replacement.Text = ""
> End With
> Selection.Find.Execute

> If Selection.Information(wdWithInTable) = False Then GoTo
> front10

> GoTo above10

> finish10:

> '11. Replaces regular hyphens with nonbreaking hyphens
> Selection.HomeKey Unit:=wdStory
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = "-"
>         .Replacement.Text = "^~"
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
>     With Selection.Find
>         .Text = ""
>     End With
> Selection.Find.Execute

> '12. Changes underlining to italics
> Selection.Find.ClearFormatting
> Selection.Find.Font.Underline = wdUnderlineSingle
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find.Replacement.Font
>         .Italic = True
>         .Underline = wdUnderlineNone
>     End With
>     With Selection.Find
>         .Text = ""
>         .Replacement.Text = ""
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll

> '13. Changes all bolded text to regular text
> Selection.Find.ClearFormatting
> Selection.Find.Font.Bold = True
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find.Replacement.Font
>         .Bold = False
>         .Italic = False
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll

> '14. Removes hyphen in "non-"
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = "non^~"
>         .Replacement.Text = "non"
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
>     With Selection.Find
>         .Text = ""
>     End With
> Selection.Find.Execute

> '15. Removes hyphen in "pre-"
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = "pre^~"
>         .Replacement.Text = "pre"
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
>     With Selection.Find
>         .Text = ""
>     End With
> Selection.Find.Execute

> '16. Removes hyphen in "post-"
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = "post^~"
>         .Replacement.Text = "post"
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
>     With Selection.Find
>         .Text = ""
>     End With
> Selection.Find.Execute

> '17. Changes "low level" to "low-level"
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
>     With Selection.Find
>         .Text = "low level"
>         .Replacement.Text = "low^~level"
>     End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
>     With Selection.Find
>         .Text = ""
>     End With
> Selection.Find.Execute

> '   18. Sets up page margins, size, and layout
> With ActiveDocument.PageSetup
>     .LineNumbering.Active = False
>     .Orientation = wdOrientPortrait
>     .TopMargin = InchesToPoints(1)
>     .BottomMargin = InchesToPoints(1)
>     .LeftMargin = InchesToPoints(1)
>     .RightMargin = InchesToPoints(1)
>     .Gutter = InchesToPoints(0)
>     .HeaderDistance = InchesToPoints(0.5)
>     .FooterDistance = InchesToPoints(0.5)
>     .PageWidth = InchesToPoints(8.5)
>     .PageHeight = InchesToPoints(11)
>     .FirstPageTray = wdPrinterDefaultBin
>     .OtherPagesTray = wdPrinterDefaultBin
>     .SectionStart = wdSectionNewPage
>     .OddAndEvenPagesHeaderFooter = False
>     .DifferentFirstPageHeaderFooter = False

...

read more »



Sat, 08 May 2004 10:38:29 GMT  
 My Word 97 macros don't run in Word 2000
No, the compiler does not show the line. Thanks for the
reply.

Quote:
>-----Original Message-----
>The first thing to do is to separate these 19 sections
into 19 macros
>and run each one to pinpoint the line that trips it up.  
(Ordinarily
>the compiler would show you the code that's causing the
problem when
>it stops -- is it not doing this?)


MVP -------
>-- See the MVP FAQ at http://www.mvps.org/word -----------
----------
>------------ "Life is nothing if you're not obsessed." --
John Waters
>----------------------------------------------------------
----------
>Please reply only to the newsgroup.


>> >-----Original Message-----
>> >Hi Bp,

>> >> Some of the macros that I created in Word 97 do not
run
>> in
>> >> Word 2000. A dialog box comes up saying: "Compile
>> error:
>> >> Invalid character." What is wrong?

>> >Impossible to say without seeing the macro code (copied
>> into
>> >a message of course - no attachments, please!)

>> >Cindy Meister
>> >INTER-Solutions, Switzerland
>> >http://homepage.swissonline.ch/cindymeister
>> >http://www.mvps.org/word
>> >http://go.compuserve.com/MSOfficeForum

>> >This reply is posted in the Newsgroup; please post any
>> follow
>> >question or reply in the newsgroup and not by e-mail :-
)

>> >Thanks for responding, Cindy. Below is the code:

>> Sub prepare()
>> '
>> ' This macro:
>> '   1.  Removes deletable styles
>> '   2.  Attaches formatter and updates styles
>> '   3.  Changes all paragraphs to Body Text
>> '   4.  Removes the first line indent in Body Text
>> '   5.  Replaces two consecutive paragraph marks with
one
>> '   6.  Changes all text in all paragraphs to 11 point
>> '   7.  Replaces two consecutive spaces with one
>> '   8.  Replaces remaining white space (i.e., two or
more
>> '       consecutive spaces or tabs) with one space
>> '   9.  Removes space before a paragraph mark
>> '   10. Removes unneeded space (spaces) in tables
>> '   11. Replaces regular hyphens with nonbreaking
hyphens
>> '   12. Changes underlining to italics
>> '   13. Changes all bolded text to regular text
>> '   14. Removes hyphen in "non-"
>> '   15. Removes hyphen in "pre-"
>> '   16. Removes hyphen in "post-"
>> '   17. Changes "low level" to "low-level"
>> '   18. Sets up page margins, size, and layout
>> '   19. Hides spelling errors

>> ' Macro recorded 11/12/98
>> '
>> '1. Removes deletable styles

>> For Each Style In ActiveDocument.Styles
>>     Response = MsgBox("Do you want to delete the " &
Style
>> & _
>>         " Style?", vbYesNoCancel)
>>     If Response = vbYes Then
>>          On Error Resume Next
>>          Application.OrganizerDelete
>> Source:=ActiveDocument.Name, _
>>              Name:=Style,

Object:=wdOrganizerObjectStyles

- Show quoted text -

Quote:
>>     ElseIf Response = vbCancel Then
>>         Exit For
>>     End If
>> Next Style

>> For Each sty In ActiveDocument.Styles
>>     If sty.InUse = True Then sty.Delete
>>     On Error Resume Next
>> Next sty

>> '2. Attaches formatter and updates styles
>> With ActiveDocument
>>     .UpdateStylesOnOpen = True
>>     .AttachedTemplate = "C:\templates\formatter.dot"
>>     .UpdateStylesOnOpen = False
>> End With

>> '3. Changes all paragraphs to Body Text
>> Selection.WholeStory
>> Selection.Style = ActiveDocument.Styles("Body Text")
>> Selection.MoveUp Unit:=wdLine, Count:=1

>> '4. Removes the first line indent in Body Text
>> With ActiveDocument.Styles("Body Text").ParagraphFormat
>>     .FirstLineIndent = InchesToPoints(0)
>> End With

>> '5. Replaces two consecutive paragraph marks with one
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = "^p^p"
>>         .Replacement.Text = "^p"
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll

>> '6. Changes all text in all paragraphs to 11 point
>> Selection.WholeStory
>> Selection.Font.Size = 11
>> Selection.MoveUp Unit:=wdLine, Count:=1

>> '7. Replaces two consecutive spaces with one
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = "  "
>>         .Replacement.Text = " "
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll

>> '8. Replaces remaining white space (i.e., two or more
>> '   consecutive spaces or tabs) with one space
>> Selection.HomeKey Unit:=wdStory
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = "^w"
>>         .Replacement.Text = " "
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll
>> Selection.Find.ClearFormatting
>>     With Selection.Find
>>         .Text = ""
>>     End With
>> Selection.Find.Execute

>> '9. Removes space before a paragraph mark
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = " ^p"
>>         .Replacement.Text = "^p"
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll
>> Selection.Find.ClearFormatting
>>     With Selection.Find
>>         .Text = ""
>>     End With
>> Selection.Find.Execute

>> '10. Removes unneeded space (spaces) in tables
>> Selection.HomeKey Unit:=wdStory
>> front10:

>> Selection.GoTo What:=wdGoToTable
>>     If Selection.Information(wdWithInTable) = False Then
>>         GoTo finish10
>>     End If

>> top10:

>> Selection.Find.ClearFormatting
>> With Selection.Find
>>     .Text = " "
>>     .Replacement.Text = ""
>> End With
>> Selection.Find.Execute
>>     If Selection.Find.Found = False Then GoTo finish10
>>     If Selection.Information(wdWithInTable) = False Then
>>         GoTo front10
>>     End If

>> above10:

>> Selection.Previous(Unit:=wdCharacter, Count:=1).Select
>> If Selection.Type = wdSelectionColumn Then GoTo down10
>> Selection.Collapse Direction:=wdCollapseEnd
>> Selection.Find.ClearFormatting
>> With Selection.Find
>>     .Text = " "
>>     .Replacement.Text = ""
>> End With
>> Selection.Find.Execute
>> Selection.Next(Unit:=wdCharacter, Count:=1).Select
>> If Selection.Type = wdSelectionColumn Then GoTo down10
>> Selection.Collapse Direction:=wdCollapseEnd

>> GoTo top10

>> down10:

>> Selection.Collapse Direction:=wdCollapseEnd
>> If Selection.Type <> wdSelectionNormal Then _
>> Selection.MoveLeft Unit:=wdCharacter, Count:=2
>> If Selection.Text <> " " Then _
>> Selection.MoveRight Unit:=wdCharacter, Count:=2
>> Selection.Delete

>> Selection.Find.ClearFormatting
>> With Selection.Find
>>     .Text = " "
>>     .Replacement.Text = ""
>> End With
>> Selection.Find.Execute

>> If Selection.Information(wdWithInTable) = False Then
GoTo
>> front10

>> GoTo above10

>> finish10:

>> '11. Replaces regular hyphens with nonbreaking hyphens
>> Selection.HomeKey Unit:=wdStory
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = "-"
>>         .Replacement.Text = "^~"
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll
>> Selection.Find.ClearFormatting
>>     With Selection.Find
>>         .Text = ""
>>     End With
>> Selection.Find.Execute

>> '12. Changes underlining to italics
>> Selection.Find.ClearFormatting
>> Selection.Find.Font.Underline = wdUnderlineSingle
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find.Replacement.Font
>>         .Italic = True
>>         .Underline = wdUnderlineNone
>>     End With
>>     With Selection.Find
>>         .Text = ""
>>         .Replacement.Text = ""
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll

>> '13. Changes all bolded text to regular text
>> Selection.Find.ClearFormatting
>> Selection.Find.Font.Bold = True
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find.Replacement.Font
>>         .Bold = False
>>         .Italic = False
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll

>> '14. Removes hyphen in "non-"
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = "non^~"
>>         .Replacement.Text = "non"
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll
>> Selection.Find.ClearFormatting
>>     With Selection.Find
>>         .Text = ""
>>     End With
>> Selection.Find.Execute

>> '15. Removes hyphen in "pre-"
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = "pre^~"
>>         .Replacement.Text = "pre"
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll
>> Selection.Find.ClearFormatting
>>     With Selection.Find
>>         .Text = ""
>>     End With
>> Selection.Find.Execute

>> '16. Removes hyphen in "post-"
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = "post^~"
>>         .Replacement.Text = "post"
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll
>> Selection.Find.ClearFormatting
>>     With Selection.Find
>>         .Text = ""
>>     End With
>> Selection.Find.Execute

>> '17. Changes "low level" to "low-level"
>> Selection.Find.ClearFormatting
>> Selection.Find.Replacement.ClearFormatting
>>     With Selection.Find
>>         .Text = "low level"
>>         .Replacement.Text = "low^~level"
>>     End With
>> Selection.Find.Execute Replace:=wdReplaceAll
>> Selection.Find.ClearFormatting
>>     With Selection.Find
>>         .Text = ""
>>     End With
>> Selection.Find.Execute

>> '   18. Sets up page margins, size, and layout
>> With ActiveDocument.PageSetup
>>     .LineNumbering.Active = False
>>     .Orientation = wdOrientPortrait
>>     .TopMargin = InchesToPoints(1)
>>     .BottomMargin = InchesToPoints(1)
>>     .LeftMargin = InchesToPoints(1)
>>     .RightMargin = InchesToPoints(1)

...

read more »



Sat, 08 May 2004 11:02:54 GMT  
 My Word 97 macros don't run in Word 2000
Hi Bp,

Besides Mark's comment about breaking this up into separate
macros so that you can zero in on the error, please also
activate Option Explicit so that you can keep proper track of
the variable names you use. It's impossible to debug
something like this if it could depend on a mistyped variable
name... Option Explicit will force you to use Dim to declare
each variable name.

Quote:
> For Each Style In ActiveDocument.Styles
>     Response = MsgBox("Do you want to delete the " & Style
> & _
>         " Style?", vbYesNoCancel)
>     If Response = vbYes Then
>          On Error Resume Next
>          Application.OrganizerDelete
> Source:=ActiveDocument.Name, _
>              Name:=Style, Object:=wdOrganizerObjectStyles
>     ElseIf Response = vbCancel Then
>         Exit For
>     End If
> Next Style

> For Each sty In ActiveDocument.Styles
>     If sty.InUse = True Then sty.Delete
>     On Error Resume Next
> Next sty

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)



Sat, 08 May 2004 17:51:03 GMT  
 My Word 97 macros don't run in Word 2000
I finally got this Word 97 macro to run in Word 2000 by
deleting a comma in the code and then putting it back in.
Why this fixed the problem, I have no idea.

Quote:
>-----Original Message-----
>Hi Bp,

>Besides Mark's comment about breaking this up into
separate
>macros so that you can zero in on the error, please also
>activate Option Explicit so that you can keep proper track
of
>the variable names you use. It's impossible to debug
>something like this if it could depend on a mistyped
variable
>name... Option Explicit will force you to use Dim to
declare
>each variable name.

>> For Each Style In ActiveDocument.Styles
>>     Response = MsgBox("Do you want to delete the " &
Style
>> & _
>>         " Style?", vbYesNoCancel)
>>     If Response = vbYes Then
>>          On Error Resume Next
>>          Application.OrganizerDelete
>> Source:=ActiveDocument.Name, _
>>              Name:=Style,

Object:=wdOrganizerObjectStyles

- Show quoted text -

Quote:
>>     ElseIf Response = vbCancel Then
>>         Exit For
>>     End If
>> Next Style

>> For Each sty In ActiveDocument.Styles
>>     If sty.InUse = True Then sty.Delete
>>     On Error Resume Next
>> Next sty

>Cindy Meister
>INTER-Solutions, Switzerland
>http://homepage.swissonline.ch/cindymeister
>http://www.mvps.org/word
>http://go.compuserve.com/MSOfficeForum

>This reply is posted in the Newsgroup; please post any
follow
>question or reply in the newsgroup and not by e-mail :-)

>.



Mon, 10 May 2004 04:09:20 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Word 2000 macro running under Word 97

2. VB hooks to WORD don't seem to work with Word 2000 SP1

3. Word 97 Macros > Word XP Macros

4. Macro doesn't run under Word 2000

5. How do you send Outlook 2000 email using WORD 97 VBA Macro

6. Call a Word 97 Macro from Outlook 2000

7. Word 2000/97 new document macro problems

8. Passing Userforms to subs (Word 2000 and 2002, I did not try Word 97)

9. Why does this piece of code work with Word 97 but not Word 2000

10. Convert Word 97 WordBasic to Word 2000 VB code

11. vba problem word 97 and not word 2000

12. Diffs Between Word 2000 and Word 97?

 

 
Powered by phpBB® Forum Software