Access automating Word - Difference between Selection / ActiveDocument and GoTo (1 Viewer)

darbid

Registered User.
Local time
Today, 13:33
Joined
Jun 26, 2008
Messages
1,428
Set up is Windows 7 / Office 2007. Access code is automating Word.

The following code (which deletes page 2) works on most PCs

Code:
With objWord.ActiveDocument
        Set rng = .GoTo(What:=wdGoToPage, name:="2")
        Set rng = rng.GoTo(What:=wdGoToBookmark, name:="\page")
        rng.Delete
        Set rng = Nothing
    End With
However I have one PC where the first line does not go to the page.
Code:
.GoTo(What:=wdGoToPage, name:="2")
I have found a workaround of using the Selection object like this (where objWord is the main Word Application object)
Code:
Set rng = objWord.Selection.GoTo(What:=wdGoToPage, name:="2")
I have also tried http://word.mvps.org/faqs/macrosvba/SelectCurPage.htm a few variations such as what is suggested here.

Can anyone help me to understand why I cannot do this from the Document (ActiveDocument) but I can from the Selection.

Also why does it work on some PCs and not on others.
 

static

Registered User.
Local time
Today, 12:33
Joined
Nov 2, 2015
Messages
823
AFAIK, selection is just the range in the document that is selected, like you've highlighted it with your mouse.
So unless you've done the equivalent of ctrl+a to select everything it wont cover the whole document.

+
unless, "represents the insertion point if nothing in the document is selected" covers it.
 

Users who are viewing this thread

Top Bottom