Herb,
I am using this setup right now:
I have a Class module (MyClass1)with this code:
Option Explicit
Private WithEvents mThisWordApp As Word.Application
Private Sub Class_Initialize()
Set mThisWordApp = Word.Application
End Sub
Private Sub mThisWordApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI
As Boolean, Cancel As Boolean)
Selecting.QuickSaveMark
End Sub
I have code in the Normal Project that initiates the Class when my Word
application is launched:
Option Explicit
Private oMyClass As MyClass
Sub AutoExec()
SetMyClass
End Sub
Sub SetMyClass()
Set oMyClass = New MyClass
End Sub
I have these procedures in a standard module of my Normal Project named
"Selecting"
Sub QuickSaveMark()
Dim i As Long
Dim oBMs As Bookmarks
On Error GoTo Err_Handler
Set oBMs = ActiveDocument.Bookmarks
On Error GoTo 0
If Not oBMs.Exists("QuickSaveMark_1") Then
oBMs.Add "QuickSaveMark_1", Selection.Range
Else
On Error Resume Next
oBMs.Add "QuickSaveMark_5", oBMs("QuickSaveMark_4").Range
oBMs.Add "QuickSaveMark_4", oBMs("QuickSaveMark_3").Range
oBMs.Add "QuickSaveMark_3", oBMs("QuickSaveMark_2").Range
oBMs.Add "QuickSaveMark_2", oBMs("QuickSaveMark_1").Range
oBMs.Add "QuickSaveMark_1", Selection.Range
On Error GoTo 0
End If
ActiveDocument.Variables("QMIndex").Value = "0"
Exit Sub
Err_Handler:
End Sub
Sub GoToQM()
Dim oVars As Variables
Dim pGetValue As String
Dim i As Long
Set oVars = ActiveDocument.Variables
On Error GoTo Err_Handler_1
pGetValue = oVars("QMIndex").Value
On Error GoTo 0
i = CLng(pGetValue)
i = i + 1
On Error GoTo Err_Handler_2
Select Case i
Case Is = 1
ActiveDocument.Bookmarks("QuickSaveMark_1").Range.Select
oVars("QMIndex").Value = "1"
Case Is = 2
ActiveDocument.Bookmarks("QuickSaveMark_2").Range.Select
oVars("QMIndex").Value = "2"
Case Is = 3
ActiveDocument.Bookmarks("QuickSaveMark_3").Range.Select
oVars("QMIndex").Value = "3"
Case Is = 4
ActiveDocument.Bookmarks("QuickSaveMark_4").Range.Select
oVars("QMIndex").Value = "4"
Case Is = 5
ActiveDocument.Bookmarks("QuickSaveMark_5").Range.Select
oVars("QMIndex").Value = "0"
End Select
On Error GoTo 0
Exit Sub
Err_Handler_1:
oVars("QMIndex").Value = "0"
Resume
Err_Handler_2:
If ActiveDocument.Bookmarks.Exists("QuickSaveMark_1") Then
ActiveDocument.Bookmarks("QuickSaveMark_1").Range.Select
Else
MsgBox "A QuickSaveMark reference is not set in this document."
End If
End Sub
Sub ClearQMs()
On Error Resume Next
With ActiveDocument
.Variables("QMIndex").Delete
.Bookmarks("QuickSaveMark_5").Delete
.Bookmarks("QuickSaveMark_4").Delete
.Bookmarks("QuickSaveMark_3").Delete
.Bookmarks("QuickSaveMark_2").Delete
.Bookmarks("QuickSaveMark_1").Delete
End With
On Error GoTo 0
End Sub
I put three buttons on my QAT to set a QuickMark, goto back to a QuickMark
and clear the QuickMarks. I just use the QAT to go back to the last
QuickMark when a document is opened. That could be set to Shift+F5 or the
code could easily be adapapted to goto the last QuickMark when a document is
opened.
I am pretty satisfied with the code. The only thing I want to revise when I
get the time is to not set the Quickmark automatically when I open and
modify templates.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Herb Tyson [MVP] wrote:
> That is correct. I works in Word 2007 for .doc format documents, but
> not for the new .docx format.
>
> It is possible to accomplish the objective in Word 2007 by using a
> combination of AutoClose and AutoOpen macros. The AutoClose macro
> would save the last location when the document is closed, and the
> AutoOpen macro would retrieve the last location when the document is
> opened. I'd be surprised if someone doesn't have just such macros
> already written. If they don't volunteer them here, you might ask for
> guidance in one of the word.vba newsgroups.
>
>> Unfortunately I am using Word 2007 and Vista (Let's not start that
>> discussion)- and youre right it doesnt work, but thank you for the
>> tip; it
>> seems to work on documents sent to me by others using Word 2003. I
>> am grateful for your time.
>>
>> Big Hug,
>> Richard
>>
>>
>>
>> "Suzanne S. Barnhill" wrote:
>>
>>> If you are using Word 2003 or earlier, you can press Shift+F5 to
>>> return to
>>> the last edit point. Unfortunately, this doesn't work in Word 2007.
>>> Word has
>>> never automatically opened at the last edit point. It may well be
>>> that WordPerfect does, or you might be thinking of Excel, which
>>> also does. --
>>> Suzanne S. Barnhill
>>> Microsoft MVP (Word)
>>> Words into Type
>>> Fairhope, Alabama USA
>>>
>>> "TheDr" <(E-Mail Removed)> wrote in message
>>> news:87451021-E4E1-4A9E-A221-(E-Mail Removed)...
>>>> I work with very large documents, and find it cumbersome to search
>>>> for the
>>>> spot I was working on when I last closed the document. Older
>>>> versions of
>>>> Office products did this automatically...... or was that word
>>>> perfect?