PDA

View Full Version : Formatting Paragraphs



mdmackillop
10-29-2009, 10:56 AM
I programme so little in Word these days, I'm forgetting the basics!

I'm importing data from Excel. It's all cleaned up, but I need to adjust indents based on Excel indents to I've added * or # to represent different indent levels. Simply, I want to look in each paragraph for this leading character, and change the Tab/Indent accordingly.




Dim p As Paragraph
For Each p In ActiveDocument.Paragraphs
With p.ParagraphFormat 'Error here @@@@@@@@@@
If Left(p, 1) = "*" Then
.TabStops(CentimetersToPoints(1.5)).Position = _
CentimetersToPoints(3.25)
.LeftIndent = CentimetersToPoints(3.25)
End If
If Left(p, 1) = "#" Then
.TabStops(CentimetersToPoints(1.5)).Position = _
CentimetersToPoints(2.25)
.LeftIndent = CentimetersToPoints(2.25)
End If
End With
Next

lucas
10-29-2009, 11:09 AM
Malcolm, I feel squeamish trying to suggest a solution for you but what if you applied a style to the paragraph?

fumei
10-29-2009, 11:57 AM
Well shush ma mouth. Styles?

As for the error:
With p.ParagraphFormat 'Error here @@@@@@@@@@

Indeed it is. ParagraphFormat is not a choice with
p - a declared Paragraph object.

If you look up the properties of the Paragraph object, ParagraphFormat is NOT one of them. Which is, admitedly, a little weird. It is, however, a property of Range.
With p.Range.ParagraphFormat


I too feel a wee squeamish about suggesting something to Malcolm, but I have to go along with Steve. Style.

mdmackillop
10-29-2009, 03:51 PM
Thanks both.
I do use Styles in the document. This is a quick and dirty fix to get a result. and adding Range I've got this working

Dim p As Paragraph
For Each p In ActiveDocument.Paragraphs
If InStr(1, p.Range.Text, "#") > 1 Then
p.Range.ParagraphFormat.TabStops(CentimetersToPoints(1.5)).Position = _
CentimetersToPoints(3.25)
p.LeftIndent = CentimetersToPoints(3.25)
p.FirstLineIndent = CentimetersToPoints(-3.25)
End If

If InStr(1, p.Range.Text, "*") > 1 Then
p.Range.ParagraphFormat.TabStops(CentimetersToPoints(1.5)).Position = _
CentimetersToPoints(2.25)
p.LeftIndent = CentimetersToPoints(2.25)
p.FirstLineIndent = CentimetersToPoints(-2.25)
End If
Next


Applying styles to indented paragraphs is not a problem. I do have 3 other styles, which appear as follows.

L30 STAIRS / WALKWAYS / BALUSTRADES
Galvanised Steel; Spec L30/550
Isolated balustrades

Any suggestions as to the best way to test these so that I can apply the appropriate styles?

fumei
11-03-2009, 09:41 AM
What do you mean "test these"? Are you asaying they are manually formatted, and you want to change them into Styles?

mdmackillop
11-03-2009, 11:22 AM
Hi Gerry,
We have a measurement programme for producing contract documentation. A Client has asked for a Word version of the document.
I can output to Excel and the non-indented items appear as above. This is set by the programme as Levels 1 - 3, so the text is not Manually formatted.
Formatting as styles will allow proper handling of orphan items etc, and insertion of additional items based on previous paragraph formats.

I suppose I can count upper case characters, and check for underlining. I was wondering if there was a "smarter" way.

fumei
11-03-2009, 12:06 PM
I do not understand:

"This is set by the programme as Levels 1 - 3, so the text is not Manually formatted. "

ALL paragraphs have an attached style. It can be one of:

1. a user defined style that has not being manually formatted;

2. a user defined style that HAS been manually formatted;

3. a built-in style that has not been manually formatted;

4. a built-in style that HAS been manually formatted.

There are no other choices. So....by "Level 1 - 3", do you mean:

L30 STAIRS / WALKWAYS / BALUSTRADES

is - I am guessing here - a Heading 1 style? This is a built-in style.

What does Word show as the used Style for L30 STAIRS / WALKWAYS / BALUSTRADES?

mdmackillop
11-03-2009, 02:14 PM
Hi Gerry,
I'll post a small sample tomorrow.

mdmackillop
11-04-2009, 03:53 AM
Sample files; Original Excel and imported/processed word document.

fumei
11-05-2009, 09:56 AM
OK, those "Level" styles appear to be real styles.

What, exactly, are you wanting to do? I do not see the instances of "*" and "#" you mention.

There are some manually formatted paragraphs.

Fabricated; Grade S275 IS a style - Level 3 (Arial, 11 pt, Bold, Underline)

but....

Surface preparation; Blast cleaning to SA 2.5

is the exact same format (Arial, 11 pt, Bold, Underline), but is the dreaded Normal + Font:Bold, Underline - i.e Normal style, manually formatted.