-
In my exceptionally well formatted documents, I always use SpaceAfterParagraph settings (to avoid the extraneous pilcrows), which can be adjusted very simply by code.
eg
[VBA]
Sub PatraSpace()
Selection.WholeStory
With Selection.ParagraphFormat
If .SpaceAfter = 12 Then
.SpaceAfter = 9
Else
.SpaceAfter = 12
End If
End With
Selection.HomeKey Unit:=wdStory
End Sub
[/VBA]
-
My, my. Perhaps we should ALL have MD exceptionally format our documents. ROFL!!
-
Princess Anne, you are a riot!
-
Hi DB
Here's a wee (wee; Scots dialect word meaning small or to pee) routine to get rid of the EEPs.
[VBA]
Sub OffWithThePees()
'Thanks to brettdj for the Replace
Const FntSize = 12
MyStr = "^p"
For i = 10 To 2 Step -1
pilcrows = Replace(Space(i), " ", MyStr)
DoSpace = (i-1) * FntSize
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.ParagraphFormat
.SpaceAfter = DoSpace
End With
With Selection.Find
.Text = pilcrows
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub
[/VBA]
-
you can also use the Chr function as in Chr(13) to search for hard line feeds and pillcrows. Its especially useful for cells in tables which have a hardline feed that isn't a hard line feed. I discovered this while pulling text in and out of a table and it kept adding extra lines :)
-
So, sandam. Are you saying that an "end of cell marker" is a Chr(13)? I have been looking for that information...someone wants to find the end of cell marker and insert a space in front of it. (I don't know where that question is anymore!)
-
Yup - it was so frustrating for a while but then after a little F1 searching I found VBA has two very useful functions for string and characters Chr and Asc. I used Asc(selection.text) on a blank cell and lo and behold the returned value was 13. I have a couple of nifty procedures to manipulate strings aren't provided by VBA (or are but not to do what I want) and I'm trying to tie them up into a Kb entry (after I get back from vacation :)). Another useful tip is looking at the ascii tables provided in VBA. Especially for numbers 0-127 - i use these to search through strings when StrComp etc. just won't do. :)
And for the end of cell marker space question - try this (I know its not totally effecient but it should work.
[vba]
Dim countChars as integer
Dim temp as string
Dim fRange as Range
ActiveDocument.Tables.Item(x).Cell(I,J).Select 'x = number of table in document
fRange = Selection.Range
temp = ""
For countChars = 1 to fRange.Characters.Count
If countChars = fRange.Characters.Count
temp = temp + " " + Asc(fRange.Characters.Count)
Else
temp = temp + Asc(fRange.Characters.Count)
End if
Next countChars
[/vba]
-
Chr(13) is a carriage return. It is not an end of cell marker.
The end of cell marker is an awkward beast. You cannot search for it, you cannot change it, you cannot, really, do much with it at all.
Try this:
In Word, type a few characters, then a paragraph mark (hit return). then insert a table and enter some text in the first couple of cells. Hit ctrl+home to go to the beginning. Ctrl+f to bring up Find - check "Use Wildcards" and look for * (or ? if you like). Now keep hitting find next and watch as it steps through the characters - it will select each one in turn, including the paragraph mark (whether or not you have them displayed), but inside the table it will skip from the last character of one cell to the first of the next without selecting the end of cell marker - it is not a proper character.
Now try this
Select a cell
Paste this code somewhere and run it
[VBA]Sub seecell()
Dim ch
For Each ch In Selection.Characters
MsgBox Len(ch) & " " & Asc(ch) & " " & Asc(Right(ch, 1))
Next
End Sub[/VBA]
It will give you a msgbox for each character in the cell - showing 1 nn nn where 1 is the length of the character and nn is the ascii code for the character - except for the last character which is the end of cell mark, when it will show 2 13 7. The end of cell marker is a character of length 2; the first (whatever you call half a character) is chr(13) and the second is chr(7).
Just be aware of it - you can't do anything about it.
-
true, it is a tricky one - however,and i know this is strange - by using the selection object I could overcome the end of cell marker. It might be because I'm using 2003, it might not. It was the carriage return that was playing havoc with my formatting so thats why that was the specific one I was searching for. When I pasted the cell contents into a listbox it displayed a pillcrow along with the text I selected. Maar ja ek verstaan wat jy se. dis a gevaarlikke ding dai een.
-
Hi sandam,
Afrikaans? Ik versta, maar het is geen echte Nederlands. Interesting about pasting to a listbox - I'll have to try that.
I am using 2003 too so shouldn't see any difference and I'm not entirely sure what your code is doing, but the original question (which I did see but didn't answer and also can't remember where it was) was about using Find / Replace without VBA code - and I don't think it's possible.
-
1. Use styles. I use a TableHolder style with a font size of 2.
2. Use styles. A intelligent, and proper use of Word will have absolutely no linefeed or paragraphs between paragraphs. Adding paragraphs (ie. using the Enter key) between text paragraphs to create space is poor design. Further, EVERY paragraph mark holds ALL possible object properties of a paragraph. That is, even the "empty" paragraph marks, put in to make space, contain every possible state of every possible property Even it is set to "False". Technically speaking that "blank" paragraph mark contains:
[vba] With Selection.Font
.Name = "Times New Roman"
.Size = 11
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorWhite
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 1
.Scaling = 100
.Position = 3
.Kerning = 11
.Animation = wdAnimationNone
End With
With Selection.Font
.Name = "Times New Roman"
.Size = 11
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorWhite
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 1
.Scaling = 100
.Position = 3
.Kerning = 11
.Animation = wdAnimationNone
End With
With Selection.ParagraphFormat
.LeftIndent = 0
.RightIndent = 0
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceDouble
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = 0
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
End Sub[/vba]
You can test this by creating a "blank" document - no text. Have one with no text, but a big whack of "empty" paragraph marks. Then one with no text, and no paragraph marks. Take a look at the file sizes. True, it does not make that much difference in small documents, but on large ones - anything over 100 pages - it does make a difference.
Word is designed to use styles. After all, ALL paragraphs have a style, whether you like it or not. It is far better to use them.