Scroll a Word doc programmatically

J

Joan Xiao

I'd like to have a Word doc scrolled to a desired location when user opens
it. How can this be done programmatically?

Thanks very much for your help.
 
J

Joan Xiao

Thanks Anne for the reply. However, I tried the code and it doesn't work for
me. I even downloaded the Word doc, but it doesn't work. I have Windows XP
Professional and Word 2003.

The article says "Place selection point at whatever location you want to
mark." to test the code. I assume this means moving the mouse to the desired
location? Anyway, I tried using the mouse, with and without scrolling, or
mving down using the arrow key, and saved the document afterwards, but it
didn't go to the last location when I re-opened it.

I'd appreciate it if you could help me further.

Thanks.

Joan
 
A

Anne Troy

Are you allowing macros to run, Joan? Tools-->Macro-->Security, must be
medium (preferred) or low. If you aren't allowing the macro to run, nothing
will happen. :)
************
Anne Troy
www.OfficeArticles.com
 
J

Joan Xiao

Thanks again Anne.

You are right, my macro security was set to high. After I change it to
medium, it works!

As you can tell, I'm a dummy in VB -- I'm a Java developer and don't know
anything about VB programming in Word, but I need to explore and see whether
VB can achieve what I need do.

I have a web application which launches a Word doc. Depending on user input,
I'd like to have the Word doc opened at a desired location automatically. So
I guess I need create bookmarks for all key words and when a user opens the
doc, one of the bookmarks needs to be selected depending on the value of the
input. How can I pass the parameter to Word?

Do you think this can be done? If not, let's forget about the web
application, how can this be done in Word itself?

I greately appreciate your help.

Joan
 
G

Greg Maxey

Joan,

I'm not Anne and I don't know how to do it with a web application, but from
within Word you could do it something like this:

Sub Document_Open()
Selection.GoTo What:=wdGoToBookmark, Name:="Test"
End Sub

Where "Test" is one of the named bookmarks.
 
G

Greg Maxey

Anne,

I just answered half the question. Standing by for one of the Senseis to
come along and answer the complete question ;-)
 
H

Helmut Weber

Hi everybody,

this one works for me, and hardly anything else,
except one could use another object to scroll into view.

Public Sub autoopen()
Application.OnTime When:=Now + TimeValue("00:00:02"), _
Name:="PlaceMe"
End Sub

Sub PlaceMe()
ActiveWindow.ScrollIntoView ActiveDocument.Bookmarks("Mark1").Range
End Sub

Some refinements or error handling possible.

Helmut Weber
 
J

Joan Xiao

Thanks everyone for your post. The information you provided has been
definitely very helpful.

So is it possible to pass a parameter to Word somehow? My feeling is that it
isn't possible, espeically because in a web application, Word is launched by
a browser and I just don't see how any parameter can be set.

An alternative for me is to dynamically create the macros. For example, read
a plain Word doc (with no macros), create a macro on the fly and then insert
it into the original doc. But then I need know how macros are stored in a
Word doc. Has anyone done something like this? Where can I find any
information related to this?

Thanks a lot.

Joan
 
J

Jean-Guy Marcil

Joan Xiao was telling us:
Joan Xiao nous racontait que :
Thanks everyone for your post. The information you provided has been
definitely very helpful.

So is it possible to pass a parameter to Word somehow? My feeling is
that it isn't possible, espeically because in a web application, Word
is launched by a browser and I just don't see how any parameter can
be set.

An alternative for me is to dynamically create the macros. For
example, read a plain Word doc (with no macros), create a macro on
the fly and then insert it into the original doc. But then I need
know how macros are stored in a Word doc. Has anyone done something
like this? Where can I find any information related to this?

You can have a VB Script on a Web page that will create a Word document.
Also, I believe that VB Scripting can read info from the Web page.
So, it seems that you could read a field content, store it in a variable,
create/open the Word document, and, from within the VB Script run some code
passing it the variable you got prior to creating the Word object.

In pseudocode:

myVar = WebPageControlContent
WordDoc = Open Word Document
WordDoc.GoTo What:=wdGoToBookmark, Name:=myVar



--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Joan Xiao

Thanks Jean for the reply. The problem is that my web application is Java
(J2EE) based, so I don't think it can execute any code in VBA.

Does anyone know how Word stores a macro in a doc? I'm really thinking af
programmatically creating the macros and insert them into Word docs.

Thanks.

Joan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top