Saving a Word 2007 document

L

Legal Learning

When saving a Word 2007 document, the insertion point is thrown to the top of
the document. Does anyone know how to stop this brain-damage?
 
G

Graham Mayor

Documents always open with the cursor at the start. With Word 2007 you can
work around it easily enough with a couple of macros in the normal template
to mark, then open the document where you left off e.g.

Sub OpenAt()
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="OpenAt"
End Sub

Added to a keyboard shortcut or to a button on the QAT, when run it will
insert a bookmark at the cursor position called OpenAt. Or you could
incorporate the command line in a macro to intercept the Save and Save as
functions to mark the last cursor position before saving the document.

The following macro will check for that bookmark and select it if present
when a document is opened.

Sub AutoOpen()
If ActiveDocument.Bookmarks.Exists("OpenAt") = True Then
ActiveDocument.Bookmarks("OpenAt").Select
End If
End Sub

http://www.gmayor.com/installing_macro.htm


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

grammatim

It _sounded_ like Legal Learning was saying that whenever he saves a
document, the cursor flips to the beginning of the document.

Wouldn't the following macro need to have a part to delete the
bookmark after the file is opened? Otherwise you'll have several such
bookmarks, and the doc would always open at the first spot you closed
at.
 
G

Graham Mayor

At first I thought that might be the case, but I know of no mechanism
whereby the cursor should move while the document remains open, however it
does always revert to the start when the document is closed and re-opened.
As for the bookmark, bookmark names are unique, so using this method there
would only ever be the one bookmark. The macro repositions it when run.

If you wish to use this method transparently, as I suggested earlier, you
would need to incorporate the line to place the bookmark in the file save
and saveas routines thus

Sub FileSave()
On Error Resume Next
ActiveDocument.Bookmarks.Add Range:=Selection.Range, name:="OpenAt"
ActiveDocument.Save
End Sub

Sub FileSaveAs()
On Error Resume Next
ActiveDocument.Bookmarks.Add Range:=Selection.Range, name:="OpenAt"
Dialogs(wdDialogFileSaveAs).Show
ActiveWindow.Caption = ActiveDocument.FullName
End Sub

The Autoopen macro remains the same - though I personally have a couple of
extra lines in the one I use -

Sub AutoOpen()
ActiveWindow.Caption = ActiveDocument.FullName
ActiveWindow.View.TableGridlines = True
If ActiveDocument.Bookmarks.Exists("OpenAt") = True Then
ActiveDocument.Bookmarks("OpenAt").Select
End If
End Sub

to ensure that gridlines are always displayed and to put the filename and
path in the Word title bar.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

grammatim

I never noticed that gridline status doesn't stick upon closing (since
I rarely use it, since I rarely merge cells), but it would be nice to
have it on by default; and there certainly have been times when I've
wanted to see the full path in the title bar.

To install these three macros -- the Save, SaveAs, and AutoOpen -- do
I need to do three separate installation operations, or can I just
copy the full sequence (dropping the comment before the third one) and
the titling and spacing will make it clear that it's three items?
 
G

Graham Mayor

You can copy all three together (delete the unwanted text once pasted into
the VBA editor). As you correctly surmised the Sub/End Sub lines identify
what is a macro - see http://www.gmayor.com/installing_macro.htm .

The only problem you might encounter is if you already have macros of the
same names. That being the case incorporate the code into the original
macros. If you need any help with that, post the existing content.

If you are not encountering grid line issues, because of the types of
documents you work with, you can omit that line from the autoopen macro.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

grammatim

Nope, every macro I have has come directly from here (from you or
Greg, IIRC). I'll go ahead and do it.

Oy, what are grid line "issues"? I have tables all the time, but they
tend to be straightforward, but it's simpler for the lines to be there
than to have to go get them when they're missing. They've never
misbehaved, and no one has complained about them here ...

Thanks!
 
G

grammatim

All features work as advertised.

Nope, every macro I have has come directly from here (from you or
Greg, IIRC). I'll go ahead and do it.

Oy, what are grid line "issues"? I have tables all the time, but they
tend to be straightforward, but it's simpler for the lines to be there
than to have to go get them when they're missing. They've never
misbehaved, and no one has complained about them here ...

Thanks!
 
G

Graham Mayor

The gridline issues are simply that on opening some third party documents
and Microsoft templates the gridlines are switched off and I prefer them
always to be on.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

BBran

Hello, I was referred to this post by another and have a question if I may.

I tried what was suggested here and thought I also followed the directions
in your link for installation below. However, the process does not seem to
work for me, so I am assuming I did something wrong. In your installation
instructions you mention the macro has to be called somehow, which I
understand. I thought though, that AutoOpen, FileSave, and FileSaveAs would
be automatically executed macros. Is that not so?
 
G

Graham Mayor

When saved in the normal template
AutoOpen runs when you open an existing document
FileSave runs when you use the File Save function
FileSaveAs runs when you use the File Save As function.

When you save a document the macro adds a bookmark at the current cursor
position
When you open a document the autoopen macro looks to see if that bookmark
exists and if it does moves the cursor to its location.
The macros need to be saved in the normal template - normal.dotm
See http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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