Page 2 of 2 FirstFirst 1 2
Results 21 to 31 of 31

Thread: Solved: Extra Unwanted Page at End of Document

  1. #21
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    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]

  2. #22
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    My, my. Perhaps we should ALL have MD exceptionally format our documents. ROFL!!
    ~Anne Troy

  3. #23
    VBAX Tutor TheAntiGates's Avatar
    Joined
    Feb 2005
    Location
    Tejas
    Posts
    263
    Location
    Princess Anne, you are a riot!
    I just found a cool semi-advanced VBA page - dictionary, queue, etc. http://analystcave.com/excel-vba-dic...ta-structures/

  4. #24
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    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]
    Last edited by mdmackillop; 02-26-2005 at 03:18 PM. Reason: DoSpace corrected to (i-1)

  5. #25
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    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
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  6. #26
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    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!)
    ~Anne Troy

  7. #27
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    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]
    Last edited by sandam; 03-04-2005 at 07:32 AM. Reason: forgot a comment
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  8. #28
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  9. #29
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    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.
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  10. #30
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  11. #31
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •