VBA: Make Indent New Paragraph

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

VBA: Make Indent New Paragraph

Post by Susanto3311 »

hi all..

how to make indent for new paragraph using VBA/Macro e.g. 1 cm
please, see attached picture
thank in advance
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA: Make Indent New Paragraph

Post by HansV »

Code: Select all

Sub Indent1Cm()
    Selection.ParagraphFormat.FirstLineIndent = CentimetersToPoints(1)
End Sub
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VBA: Make Indent New Paragraph

Post by StuartR »

It would be much better to define a paragraph style for this, and then to apply that style to the relevant paragraphs. In your example if "AFTER RUN MACRO" is in a specific style then you could set that style to have a following paragraph in the 1cm indent style that you have defined.
StuartR


Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA: Make Indent New Paragraph

Post by Susanto3311 »

hi Hans, thank you!!!

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA: Make Indent New Paragraph

Post by Susanto3311 »

hi ..
the macro can't automatically in second paragraph.
i must select/block in 1st & 2nd paragraph then running code.
and how about this problem? i want not change for numbering list
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA: Make Indent New Paragraph

Post by HansV »

The macro acts on the selected text only. If you don't want to change numbered paragraphs, don't select numbered paragraphs.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15585
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA: Make Indent New Paragraph

Post by ChrisGreaves »

StuartR wrote:
10 Mar 2022, 09:28
... you could set that style to have a following paragraph in the 1cm indent style that you have defined.
... and set that style to have, as its following paragraph, the same style?
Cheers
Chris
There's nothing heavier than an empty water bottle

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA: Make Indent New Paragraph

Post by Susanto3311 »

Hi Chris, my paragraph always same style.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15585
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: VBA: Make Indent New Paragraph

Post by ChrisGreaves »

Susanto3311 wrote:
10 Mar 2022, 14:27
Hi Chris, my paragraph always same style.
Susan, please accept my apologies. I was being too lazy to explain in full.
Untitled.png
In this example I am using a paragraph style called "Body Text" (top left of the image).
I decide to Modify the style, and a second pane opens up (right-hand side).

The top-right of the image shows in that second pane that I am modifying the style "Body Text", and finally, when I tap the Enter key to start a new paragraph, then the new paragraph will continue to be in the same style - that of "Body Text".

You can create a paragraph style for the paragraph that begins "Skin Whitening products ...". let's suppose that you call this style "SusansIndent"
When you tap the Enter key after typing " ... Working Group (ZMWG) finds", the new paragraph will automatically be in the same style, that is "SusansIndent".

Even better, the paragraph style you use to type "After Run Macro" can have its following style set to "SusansIndent", so that after you have typed ""After Run Macro"" and tapped the Enter key, you will automatically be in the style "SusansIndent"

Cheers
Chris
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA: Make Indent New Paragraph

Post by Susanto3311 »

hi chris, thank you.. i will try.

User avatar
Charles Kenyon
5StarLounger
Posts: 609
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: VBA: Make Indent New Paragraph

Post by Charles Kenyon »

Note, if you are using automatic numbering, the indent for that is controlled, not in the style, but in the Define New MultiLevel List dialog.
See http://www.shaunakelly.com/word/numberi ... 72010.html.
The numbered items should be using a different paragraph style from your Body Text style, although it can be based on the Body Text style.

I would be handling this through your styles and not involving vba at all.