[bump 3]
Boy, this is old. Recently I got more involved in Word's object model, and I did in fact find a solution to this issue, using
this tip found on the
Microsoft Word MVP FAQ Site.
I don't know if the OP even uses TSG anymore, but here it is for future readers:
Code:
Option Explicit
Public Sub CollapseDoc()
Dim doc As Document
Dim rng As Range
Dim strDoc As String
Dim strPage As String
Dim i As Integer
Const PAGE_BREAK_START As String = "========================= Page "
Const PAGE_BREAK_END As String = " ========================="
Set doc = Word.Application.ActiveDocument
i = 1
Do While i <= doc.Range.Information(wdNumberOfPagesInDocument)
Set rng = doc.Range(0, 0)
Set rng = rng.GoTo(what:=wdGoToPage, Name:=i)
Set rng = rng.GoTo(what:=wdGoToBookmark, Name:="\page")
With rng
strPage = .Text
strPage = Replace(strPage, vbNewLine, " ")
strPage = strPage & vbNewLine & _
PAGE_BREAK_START & i & _
PAGE_BREAK_END & vbNewLine
strDoc = strDoc & strPage
End With
i = i + 1
Loop
PostCollapsedDoc doc.Name, strDoc
End Sub
Private Sub PostCollapsedDoc(ByVal strName As String, _
ByVal strIn As String)
Dim doc As Document
Set doc = Word.Documents.Add
With doc.Range
.Text = strIn
With .Find
.Forward = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Execute Findtext:="^m", ReplaceWith:="", Replace:=wdReplaceAll
End With
.Paragraphs.SpaceBefore = 6
With .Font
.Name = "Tahoma"
.Size = 8
End With
End With
With Word.Application.Dialogs(wdDialogFileSaveAs)
.Name = "Collapse_of_" & strName
.Show
End With
End Sub
This works best in a document that has no tables or other objects (like textboxes, images, or form fields). I wasn't sure what the OP meant by "dead space," so I basically trimmed hard carriage returns and manual page breaks.
Anyway, I came across that method to select a specific page today and thought I'd post a solution for this thread in case anybody needs it or the model on which it's based.
HTH
chris.
[edit]
Attached a couple of samples.
[/edit]