Dear Experts,
I got a long word-file where the user has inserted spaces (1 to n)
after the tab of the built-in heading styles (featuring hanging
indents) and before the text of the headings. Example

1.1Tab(HangingIndent)RedundantLeadingSpacesHeadingText

But it should be:
1.1Tab(HangingIndent)HeadingText

So how can I programmatically (VBA) drop these redundant leading
spaces?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Re: Delete any leading (redundant) spaces after tab of built-in-heading styles by Greg

Greg
Sun Mar 02 14:08:52 PST 2008

Andreas,

You might have to change or add to the Cases of "Heading" styles but this
might work.

Sub ScratchMacro()
Dim oPar As Word.Paragraph
Dim oRng As Word.Range
For Each oPar In ActiveDocument.Paragraphs
Select Case oPar.Style
Case "Heading 1", "Heading 2"
Set oRng = oPar.Range
With oRng.Find
.Text = "(^t)( )@([! ])"
.Replacement.Text = "\1\3"
.MatchWildcards = True
.Execute Replace:=wdReplaceOne
End With
Case Else
'Do nothing
End Select
Next oPar
End Sub


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~


"andreas" <andreas.hermle@gmx.de> wrote in message
news:316cbe83-fed6-48b3-a5e6-00219fc76890@h11g2000prf.googlegroups.com...
> Dear Experts,
> I got a long word-file where the user has inserted spaces (1 to n)
> after the tab of the built-in heading styles (featuring hanging
> indents) and before the text of the headings. Example
>
> 1.1Tab(HangingIndent)RedundantLeadingSpacesHeadingText
>
> But it should be:
> 1.1Tab(HangingIndent)HeadingText
>
> So how can I programmatically (VBA) drop these redundant leading
> spaces?
>
> Help is much appreciated. Thank you very much in advance.
>
> Regards, Andreas



Re: Delete any leading (redundant) spaces after tab of built-in-heading styles by Doug

Doug
Sun Mar 02 14:16:00 PST 2008

You can do this using Edit>Replace. In the Find and Replace dialog, click
on the More button and then check the "Use wildcards" box and in the Find
what control, enter

(^t)[ ]{1,}

and in the Replace with control, enter

\1

Then click on Replace All

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"andreas" <andreas.hermle@gmx.de> wrote in message
news:316cbe83-fed6-48b3-a5e6-00219fc76890@h11g2000prf.googlegroups.com...
> Dear Experts,
> I got a long word-file where the user has inserted spaces (1 to n)
> after the tab of the built-in heading styles (featuring hanging
> indents) and before the text of the headings. Example
>
> 1.1Tab(HangingIndent)RedundantLeadingSpacesHeadingText
>
> But it should be:
> 1.1Tab(HangingIndent)HeadingText
>
> So how can I programmatically (VBA) drop these redundant leading
> spaces?
>
> Help is much appreciated. Thank you very much in advance.
>
> Regards, Andreas



Re: Delete any leading (redundant) spaces after tab of by andreas

andreas
Mon Mar 03 03:19:59 PST 2008

On 2 Mrz., 23:16, "Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org>
wrote:
> You can do this using Edit>Replace. =A0In the Find and Replace dialog, cli=
ck
> on the More button and then check the "Use wildcards" box and in the Find
> what control, enter
>
> (^t)[ ]{1,}
>
> and in the Replace with control, enter
>
> \1
>
> Then click on Replace All
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "andreas" <andreas.her...@gmx.de> wrote in message
>
> news:316cbe83-fed6-48b3-a5e6-00219fc76890@h11g2000prf.googlegroups.com...
>
>
>
> > Dear Experts,
> > I got a long word-file where the user has inserted spaces (1 to n)
> > after the tab of the built-in heading styles (featuring hanging
> > indents) and before the text of the headings. Example
>
> > 1.1Tab(HangingIndent)RedundantLeadingSpacesHeadingText
>
> > But it should be:
> > 1.1Tab(HangingIndent)HeadingText
>
> > So how can I programmatically (VBA) drop these redundant leading
> > spaces?
>
> > Help is much appreciated. Thank you very much in advance.
>
> > Regards, Andreas- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Doug,

thanks for your quick help. I am getting an error message, telling me
that this expression is not working (on the search and replace dialog
field). I altered the expression to
(^t) {1,} and replaced it with ^t . Now it works but it does not find
the tabs followed by spaces on the built-in headings (heading 1,
heading 2, heading 3). May be it cannot find tabs before the built-in
headings since the tab ist part of the underlying field of the
heading. I hope I made myself clear.

Regards, Andreas

Re: Delete any leading (redundant) spaces after tab of by andreas

andreas
Mon Mar 03 03:27:41 PST 2008

On 2 Mrz., 23:08, "Greg Maxey" <gma...@mvps.oSCARrOMEOgOLF> wrote:
> Andreas,
>
> You might have to change or add to the Cases of "Heading" styles but this
> might work.
>
> Sub ScratchMacro()
> Dim oPar As Word.Paragraph
> Dim oRng As Word.Range
> For Each oPar In ActiveDocument.Paragraphs
> =A0 Select Case oPar.Style
> =A0 =A0 Case "Heading 1", "Heading 2"
> =A0 =A0 =A0 Set oRng =3D oPar.Range
> =A0 =A0 =A0 With oRng.Find
> =A0 =A0 =A0 =A0 .Text =3D "(^t)( )@([! ])"
> =A0 =A0 =A0 =A0 .Replacement.Text =3D "\1\3"
> =A0 =A0 =A0 =A0 .MatchWildcards =3D True
> =A0 =A0 =A0 =A0 .Execute Replace:=3DwdReplaceOne
> =A0 =A0 =A0 End With
> =A0 =A0 Case Else
> =A0 =A0 =A0 'Do nothing
> =A0 End Select
> Next oPar
> End Sub
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Greg Maxey - =A0Word MVP
>
> My web sitehttp://gregmaxey.mvps.org
> Word MVP web sitehttp://word.mvps.org
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> "andreas" <andreas.her...@gmx.de> wrote in message
>
> news:316cbe83-fed6-48b3-a5e6-00219fc76890@h11g2000prf.googlegroups.com...
>
>
>
> > Dear Experts,
> > I got a long word-file where the user has inserted spaces (1 to n)
> > after the tab of the built-in heading styles (featuring hanging
> > indents) and before the text of the headings. Example
>
> > 1.1Tab(HangingIndent)RedundantLeadingSpacesHeadingText
>
> > But it should be:
> > 1.1Tab(HangingIndent)HeadingText
>
> > So how can I programmatically (VBA) drop these redundant leading
> > spaces?
>
> > Help is much appreciated. Thank you very much in advance.
>
> > Regards, Andreas- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Dear Greg,

thanks for the quick answer. Although I altered it slightly as you
suggested to include my specific heading style, it regrettably did not
work. As I stated below in response to Doug's suggestion, I guess the
tabs of the built-in heading styles cannot be accessed the way you
suggest. I hope I could make myself clear. Thank you for your help.
Regards, Andreas

Re: Delete any leading (redundant) spaces after tab of built-in-heading styles by Graham

Graham
Mon Mar 03 03:48:45 PST 2008


> thanks for your quick help. I am getting an error message, telling me
> that this expression is not working (on the search and replace dialog
> field). I altered the expression to
> (^t) {1,} and replaced it with ^t . Now it works but it does not find
> the tabs followed by spaces on the built-in headings (heading 1,
> heading 2, heading 3). May be it cannot find tabs before the built-in
> headings since the tab ist part of the underlying field of the
> heading. I hope I made myself clear.
>
> Regards, Andreas

My guess is that you have the regional settings in Windows to something
other than English. eg if you have the regional settings set to Germany, the
comma in {1,} will throw an error - use a semi colon {1;} instead.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



Re: Delete any leading (redundant) spaces after tab of by andreas

andreas
Mon Mar 03 07:26:01 PST 2008

On 3 Mrz., 12:48, "Graham Mayor" <gma...@REMOVETHISmvps.org> wrote:
> > thanks for your quick help. I am getting an error message, telling me
> > that this expression is not working (on the search and replace dialog
> > field). I altered the expression to
> > (^t) {1,} and replaced it with ^t . Now it works but it does not find
> > the tabs followed by spaces on the built-in headings (heading 1,
> > heading 2, heading 3). May be it cannot find tabs before the built-in
> > headings since the tab ist part of the underlying field of the
> > heading. I hope I made myself clear.
>
> > Regards, Andreas
>
> My guess is that you have the regional settings in Windows to something
> other than English. eg if you have the regional settings set to Germany, t=
he
> comma in {1,} will throw an error - use a semi colon {1;} instead.
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - =A0Word MVP
>
> My web sitewww.gmayor.com
> Word MVP web sitehttp://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Graham,

thanks for the tip, but I did consider this already.
Regards, Andreas

Re: Delete any leading (redundant) spaces after tab of built-in-heading styles by Helmut

Helmut
Mon Mar 03 07:39:22 PST 2008

Hi Andreas,

As leading spaces are no good anyway:

Sub Testxyz()
Dim oPRg As Paragraph
For Each oPRg In ActiveDocument.Paragraphs
While oPRg.Range.Characters.First = " "
oPRg.Range.Characters.First = ""
Wend
Next
End Sub

I am assuming, that you know how to add a check,
if required, if the paragraph in question is a heading paragraph.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: Delete any leading (redundant) spaces after tab of built-in-heading styles by Helmut

Helmut
Mon Mar 03 07:50:50 PST 2008

Hi Doug,

I think, Andreas has automatically numbered headings.

--

Gruß

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: Delete any leading (redundant) spaces after tab of built-in-heading styles by Helmut

Helmut
Mon Mar 03 08:07:48 PST 2008

Hi Andreas,

some more clarification:

>May be it cannot find tabs before the built-in headings
>since the tab ist part of the underlying field of the heading.

You are on the right track.

I don't know much about fields,
but there is no tab in the liststring nor at the paragraph's start.

MsgBox
Len(ActiveDocument.ListParagraphs(1).Range.ListFormat.ListString)
for e.g.
1)<tab>text, text, text...
The Liststring has a length of 2.

There is some algorithm,
that makes Word display a tab.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Re: Delete any leading (redundant) spaces after tab of by andreas

andreas
Mon Mar 03 13:02:28 PST 2008

On Mar 3, 4:39=A0pm, Helmut Weber <red....@t-online.de> wrote:
> Hi Andreas,
>
> As leading spaces are no good anyway:
>
> Sub Testxyz()
> Dim oPRg As Paragraph
> For Each oPRg In ActiveDocument.Paragraphs
> =A0 =A0While oPRg.Range.Characters.First =3D " "
> =A0 =A0 =A0 oPRg.Range.Characters.First =3D ""
> =A0 =A0Wend
> Next
> End Sub
>
> I am assuming, that you know how to add a check,
> if required, if the paragraph in question is a heading paragraph.
>
> --
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Vista Small Business, Office XP

Hi Helmut,

your code did the trick. Thank you very much. Your code is really good
since - as you mentioned - it will delete any leading spaces on any
paragraph. And this should be the case throughout the document. Again,
thank you very much. Regards, Andreas