Help!

macro runs but does not work as expected

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Application Errors RSS
Next:  Word Processor will not open up in works 8  
Author Message
Ulrike
External


Since: Dec 10, 2006
Posts: 4



PostPosted: Sun Dec 10, 2006 6:56 am    Post subject: macro runs but does not work as expected
Archived from groups: microsoft>public>word>application>errors (more info?)

Hi, I created a macro by recording search and replace actions (replacing text
as well as styles). The actions worked fine when recording the macro. The
macro runs without error - but also without any effect.

Thanks in advance for your support and best regards! Ulrike

==

Here is one of the actions of the macro:

--
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift 1")
Selection.Find.Replacement.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 Replace:=wdReplaceAll

--

And here is the whole macro (but as far as I can see, in principle the
find-replace action is just repeated with other parameters):

Sub Signum_Manuskript_Formatvorlagen()
'
' Signum_Manuskript_Formatvorlagen Makro
' Makro aufgezeichnet am 10.12.2006 von Ulrike Schäfer
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift 1")
Selection.Find.Replacement.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 Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift 1")
Selection.Find.Replacement.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 Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift 2")
Selection.Find.Replacement.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 Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
Back to top
Tony Jollans
External


Since: Aug 22, 2006
Posts: 286



PostPosted: Sun Dec 10, 2006 6:38 pm    Post subject: Re: macro runs but does not work as expected [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

The recording of macros for Find and Replace is not perfect - and the border
setting in this case is a bit suspicious. What exactly did you replace and
want to replace with what?

--
Enjoy,
Tony

"Ulrike" <Ulrike.DeleteThis@discussions.microsoft.com> wrote in message
news:E09BCBE6-5426-4540-9356-08FBC27AD4DE@microsoft.com...
> Hi, I created a macro by recording search and replace actions (replacing
> text
> as well as styles). The actions worked fine when recording the macro. The
> macro runs without error - but also without any effect.
>
> Thanks in advance for your support and best regards! Ulrike
>
> ==
>
> Here is one of the actions of the macro:
>
> --
> Selection.Find.ClearFormatting
> Selection.Find.Style = ActiveDocument.Styles("Heading 1")
> Selection.Find.ParagraphFormat.Borders.Shadow = False
> Selection.Find.Replacement.ClearFormatting
> Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift
> 1")
> Selection.Find.Replacement.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 Replace:=wdReplaceAll
>
> --
>
> And here is the whole macro (but as far as I can see, in principle the
> find-replace action is just repeated with other parameters):
>
> Sub Signum_Manuskript_Formatvorlagen()
> '
> ' Signum_Manuskript_Formatvorlagen Makro
> ' Makro aufgezeichnet am 10.12.2006 von Ulrike Schäfer
> '
> Selection.Find.ClearFormatting
> Selection.Find.Style = ActiveDocument.Styles("Heading 1")
> Selection.Find.ParagraphFormat.Borders.Shadow = False
> Selection.Find.Replacement.ClearFormatting
> Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift
> 1")
> Selection.Find.Replacement.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 Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
> Selection.Find.Style = ActiveDocument.Styles("Heading 1")
> Selection.Find.ParagraphFormat.Borders.Shadow = False
> Selection.Find.Replacement.ClearFormatting
> Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift
> 1")
> Selection.Find.Replacement.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 Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
> Selection.Find.Style = ActiveDocument.Styles("Heading 1")
> Selection.Find.ParagraphFormat.Borders.Shadow = False
> Selection.Find.Replacement.ClearFormatting
> With Selection.Find
> .Text = "^p"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = True
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Selection.Find.Execute Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
> Selection.Find.Style = ActiveDocument.Styles("Heading 2")
> Selection.Find.ParagraphFormat.Borders.Shadow = False
> Selection.Find.Replacement.ClearFormatting
> Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift
> 2")
> Selection.Find.Replacement.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 Replace:=wdReplaceAll
> Selection.Find.ClearFormatting
> Selection.Find.Style = ActiveDocument.Styles("Heading 2")
> Selection.Find.ParagraphFormat.Borders.Shadow = False
> Selection.Find.Replacement.ClearFormatting
> With Selection.Find
> .Text = "^p"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = True
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> End Sub
Back to top
Ulrike
External


Since: Dec 10, 2006
Posts: 4



PostPosted: Wed Dec 13, 2006 12:09 am    Post subject: Re: macro runs but does not work as expected [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

What I wanted to do (for example; the other actions do in principle the same
thing):

* replace style "Heading 1" in lines containing "(" with style "Überschrift
1".

I did this by searching for style "Heading 1" + character "(", replacing
with "Überschrift 1" and character "(".

* replace remaining style "Heading 1" + paragraph with nothing (in fact,
deleting empty lines with style "Heading 1")

I did not intentionally define any border settings in this macro. Maybe I
should delete the definitions concerning borders, e.g.
Selection.Find.ParagraphFormat.Borders.Shadow = False?

Regards!
Ulrike

"Tony Jollans" wrote:

> The recording of macros for Find and Replace is not perfect - and the border
> setting in this case is a bit suspicious. What exactly did you replace and
> want to replace with what?
>
> --
> Enjoy,
> Tony
>
> "Ulrike" <Ulrike RemoveThis @discussions.microsoft.com> wrote in message
> news:E09BCBE6-5426-4540-9356-08FBC27AD4DE@microsoft.com...
> > Hi, I created a macro by recording search and replace actions (replacing
> > text
> > as well as styles). The actions worked fine when recording the macro. The
> > macro runs without error - but also without any effect.
> >
> > Thanks in advance for your support and best regards! Ulrike
> >
> > ==
> >
> > Here is one of the actions of the macro:
> >
> > --
> > Selection.Find.ClearFormatting
> > Selection.Find.Style = ActiveDocument.Styles("Heading 1")
> > Selection.Find.ParagraphFormat.Borders.Shadow = False
> > Selection.Find.Replacement.ClearFormatting
> > Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift
> > 1")
> > Selection.Find.Replacement.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 Replace:=wdReplaceAll
> >
> > --
> >
> > And here is the whole macro (but as far as I can see, in principle the
> > find-replace action is just repeated with other parameters):
> >
> > Sub Signum_Manuskript_Formatvorlagen()
> > '
> > ' Signum_Manuskript_Formatvorlagen Makro
> > ' Makro aufgezeichnet am 10.12.2006 von Ulrike Schäfer
> > '
> > Selection.Find.ClearFormatting
> > Selection.Find.Style = ActiveDocument.Styles("Heading 1")
> > Selection.Find.ParagraphFormat.Borders.Shadow = False
> > Selection.Find.Replacement.ClearFormatting
> > Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift
> > 1")
> > Selection.Find.Replacement.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 Replace:=wdReplaceAll
> > Selection.Find.ClearFormatting
> > Selection.Find.Style = ActiveDocument.Styles("Heading 1")
> > Selection.Find.ParagraphFormat.Borders.Shadow = False
> > Selection.Find.Replacement.ClearFormatting
> > Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift
> > 1")
> > Selection.Find.Replacement.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 Replace:=wdReplaceAll
> > Selection.Find.ClearFormatting
> > Selection.Find.Style = ActiveDocument.Styles("Heading 1")
> > Selection.Find.ParagraphFormat.Borders.Shadow = False
> > Selection.Find.Replacement.ClearFormatting
> > With Selection.Find
> > .Text = "^p"
> > .Replacement.Text = ""
> > .Forward = True
> > .Wrap = wdFindContinue
> > .Format = True
> > .MatchCase = False
> > .MatchWholeWord = False
> > .MatchWildcards = False
> > .MatchSoundsLike = False
> > .MatchAllWordForms = False
> > End With
> > Selection.Find.Execute Replace:=wdReplaceAll
> > Selection.Find.ClearFormatting
> > Selection.Find.Style = ActiveDocument.Styles("Heading 2")
> > Selection.Find.ParagraphFormat.Borders.Shadow = False
> > Selection.Find.Replacement.ClearFormatting
> > Selection.Find.Replacement.Style = ActiveDocument.Styles("Überschrift
> > 2")
> > Selection.Find.Replacement.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 Replace:=wdReplaceAll
> > Selection.Find.ClearFormatting
> > Selection.Find.Style = ActiveDocument.Styles("Heading 2")
> > Selection.Find.ParagraphFormat.Borders.Shadow = False
> > Selection.Find.Replacement.ClearFormatting
> > With Selection.Find
> > .Text = "^p"
> > .Replacement.Text = ""
> > .Forward = True
> > .Wrap = wdFindContinue
> > .Format = True
> > .MatchCase = False
> > .MatchWholeWord = False
> > .MatchWildcards = False
> > .MatchSoundsLike = False
> > .MatchAllWordForms = False
> > End With
> > End Sub
>
>
Back to top
Ulrike
External


Since: Dec 10, 2006
Posts: 4



PostPosted: Wed Dec 13, 2006 12:55 am    Post subject: Re: macro runs but does not work as expected [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Tony Jollans" wrote:

....
> and the border setting in this case is a bit suspicious.

Thanks a lot, this seems to be the problem: I deleted the lines
"Selection.Find.ParagraphFormat.Borders.Shadow = False", and now everything
works fine!

Regards
Ulrike
Back to top
Tony Jollans
External


Since: Aug 22, 2006
Posts: 286



PostPosted: Wed Dec 13, 2006 11:38 am    Post subject: Re: macro runs but does not work as expected [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Glad you're sorted but I would be interested to know what you recorded in
order to get the border settings as they are - or if you can recreate the
situation.

--
Enjoy,
Tony

"Ulrike" <Ulrike RemoveThis @discussions.microsoft.com> wrote in message
news:F4894100-CFF7-4DE4-96EB-D2C58B618667@microsoft.com...
> "Tony Jollans" wrote:
>
> ...
>> and the border setting in this case is a bit suspicious.
>
> Thanks a lot, this seems to be the problem: I deleted the lines
> "Selection.Find.ParagraphFormat.Borders.Shadow = False", and now
> everything
> works fine!
>
> Regards
> Ulrike
Back to top
Ulrike
External


Since: Dec 10, 2006
Posts: 4



PostPosted: Wed Dec 13, 2006 11:38 am    Post subject: Re: macro runs but does not work as expected [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Yes, I could recreate the situation:

1. I create the macro by recording the following search - replace

2. I define in search field: character "(", style heading 1. I do not define
anything about bordering, and nothing is predefined (I checked this
carefully).

3. I end the macro recording, close the document without saving, reopen it.

4. I run the macro. Nothing happens.

The macro again contains the following line:
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False

When I NOW want to define a new search - replace (after running the macro),
I can see the predefined settings (from the last search - replace) in the
search - replace fields: Besides "(" and "heading 1" / "Überschrift 1", there
is also predefined in search field:

"Rahmen oben (einfache, einfarbige Linie" (in English something like "border
above, single monochrome line")

and in the replace field:

"Rahmen oben (einfache, einfarbige Linie, Autom ..." - there seems to be
added another feature, "automatic" something.

I have no idea where these settings come from. I can delete them together
with the other predefinitions (function "Keine Formatierung" - in English
something like "no format or style"). But when I repeat defining / running
the macro, it's in there again.

I hope this helps. If anything is unclear (I am struggling with my poor
English), just send me another mail.

Regards!
Ulrike

"Tony Jollans" wrote:

> Glad you're sorted but I would be interested to know what you recorded in
> order to get the border settings as they are - or if you can recreate the
> situation.
>
> --
> Enjoy,
> Tony
>
> "Ulrike" <Ulrike.DeleteThis@discussions.microsoft.com> wrote in message
> news:F4894100-CFF7-4DE4-96EB-D2C58B618667@microsoft.com...
> > "Tony Jollans" wrote:
> >
> > ...
> >> and the border setting in this case is a bit suspicious.
> >
> > Thanks a lot, this seems to be the problem: I deleted the lines
> > "Selection.Find.ParagraphFormat.Borders.Shadow = False", and now
> > everything
> > works fine!
> >
> > Regards
> > Ulrike
>
>
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Application Errors All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum