W
Walter Briscoe
I am running Office 2002.
I have Excel documents which "name" certain pages in a given Word
document. I want the Excel document to cause Word to edit that document
so it only consists of the named pages.
My model for text deletion is selection.extend; selection.gotoend;
selection.delete.
I find that selection.extend does not work.
e.g.
This does not work:
Set oWD = CreateObject("Word.Application")
With oWD
.Visible = True
.Documents.Open Filename:="C:\foo.doc", ReadOnly:=True
.Selection.Extend ' This is ineffective
' .Selection.ExtendMode = True ' This is also ineffective
.Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
.Selection.Delete Unit:=wdCharacter, Count:=1
End With
OTOH, this does work:
Set oWD = CreateObject("Word.Application")
With oWD
.Visible = True
.Documents.Open Filename:="C:\foo.doc", ReadOnly:=True
.Run "ZapTOC"
End With
where ZapTOC in foo.doc is set as:
Sub ZapTOC()
Selection.Extend
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
Can anyone here advise on such automation?
I have Excel documents which "name" certain pages in a given Word
document. I want the Excel document to cause Word to edit that document
so it only consists of the named pages.
My model for text deletion is selection.extend; selection.gotoend;
selection.delete.
I find that selection.extend does not work.
e.g.
This does not work:
Set oWD = CreateObject("Word.Application")
With oWD
.Visible = True
.Documents.Open Filename:="C:\foo.doc", ReadOnly:=True
.Selection.Extend ' This is ineffective
' .Selection.ExtendMode = True ' This is also ineffective
.Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
.Selection.Delete Unit:=wdCharacter, Count:=1
End With
OTOH, this does work:
Set oWD = CreateObject("Word.Application")
With oWD
.Visible = True
.Documents.Open Filename:="C:\foo.doc", ReadOnly:=True
.Run "ZapTOC"
End With
where ZapTOC in foo.doc is set as:
Sub ZapTOC()
Selection.Extend
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
Can anyone here advise on such automation?