From Excel, Open a word document and goto a page question [Solved/Closed]

scooble 4 Posts Monday January 28, 2013Registration date May 30, 2013 Last seen - Jan 29, 2013 at 06:21 AM - Latest reply: rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen
- Jun 1, 2013 at 06:07 PM
Hello,

I have an Excel document which I have inserted some VBA code to open a word document;

Set WordApp = CreateObject("word.Application")
WordApp.documents.Open NetworkAddress & FileName
WordApp.Visible = True


But I also want it to navigate to a page of my choosing, in this example, I have chosen page 8 as a random example;
WordApp.Selection.Goto wdGoToPage, wdGoToNext, , 8 ' trying to go to page 8


But this just opens up the document and goes to page 29, which happens to be 'section' 8

I also tried this;
Selection.Goto What:=wdGoToPage, Which:=wdGoToNext, Name:="8"

But the debugger stopped it because it thinks that there is a syntax error

Could someone please explain the full method and give an example of the code that you place in Excel to open up a word document and navigate to a specific page

BTW - the same question has been asked here;
http://www.mrexcel.com/forum/excel-q...d-go-page.html

so you could either answer here or on the other thread, I don't mind

Many thanks,
Scooble
See more 

9 replies

rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen - Jan 29, 2013 at 06:58 AM
0
Thank you
this also does not work ?
WordApp.Selection.Goto What:=wdGoToPage, Which:=wdGoToNext, Name:="8"
scooble 4 Posts Monday January 28, 2013Registration date May 30, 2013 Last seen - Jan 29, 2013 at 07:56 AM
0
Thank you
yes, your right, that doesn't work too. It opens up word and navigates to page 29 (which happens to be section 8)
rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen - Jan 29, 2013 at 10:05 PM
is it possible to sample word document that can be test. If you could post it on some public file share site like speedyshare.com and post back link to the ACTUAL FILE back here
scooble 4 Posts Monday January 28, 2013Registration date May 30, 2013 Last seen - Jan 30, 2013 at 03:55 AM
0
Thank you
I tried using a working document and it would go to section instead of page.
when I use a blank document with lets say 5 pages, it always went to page 1.

I used several different lines of code and they all went to page 1 on the blank document;

WordApp.Selection.Goto What:=wdGoToPage, Which:=wdGoToNext, Name:="5"  
WordApp.Selection.Goto What:=wdGoToPage, Count:=5 
WordApp.Selection.Goto wdGoToPage, wdGoToNext, , 5  


does it work with you?
rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen - Feb 2, 2013 at 02:13 PM
Ah I see
The issue is this, you are trying to run the code from non- word application. It does not know what these mean "wdGoToPage", "wdGoToNext"

Try this
WordApp.Selection.Goto What:=1, Which:=2, Name:="8"
rizvisa1, thank you so much. Had the exact same problem. This cleared it up.
rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen - Mar 16, 2013 at 11:56 AM
you are welcome anon.
scooble 4 Posts Monday January 28, 2013Registration date May 30, 2013 Last seen - May 30, 2013 at 09:18 AM
0
Thank you
thats great, and it seems to work, however, what do these numbers mean?
What:=1, Which:=2,
rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen - Jun 1, 2013 at 06:07 PM
from help

Word Developer Reference
Document.GoTo Method
Returns a Range object that represents the start position of the specified item, such as a page, bookmark, or field.
Syntax

expression.GoTo(What, Which, Count, Name)

expression Required. A variable that represents a Document object.

Parameters

Name Required/Optional Data Type Description
What Optional. Variant .
The kind of item to which the range or selection is moved. Can be one of the WdGoToItem constants.

Which . Optional. Variant.
The item to which the range or selection is moved. Can be one of the WdGoToDirection constants.

Count . Optional. Variant.
The number of the item in the document. The default value is 1. Only positive values are valid. To specify an item that precedes the range or selection, use wdGoToPrevious as the Which argument and specify a value for the Count value.

Name Optional. Variant.
If the What argument is wdGoToBookmark, wdGoToComment, wdGoToField, or wdGoToObject, this argument specifies a name. Only positive values are valid. To specify an item that precedes the range or selection, use wdGoToPrevious as the Which argument and specify a value for the Count argument.

Remarks
When you use the GoTo method with the wdGoToGrammaticalError, wdGoToProofreadingError, or wdGoToSpellingError constant, the Range that's returned includes any grammar error text or spelling error text.

Too Much detail to add here. See the help and you will find all you seek