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.