'This file is distributed "as is", e.g. there are no warranties 'and obligations and you could use it in your applications on your 'own risk. Although your comments and questions are welcome. ' 'Author: (c) Dan Kozub, 1999 'URL : http://DanKozub.com 'Email : mail@DanKozub.com 'Last Modified: March 24,1999 'Version: 1.4 'Revision history: ' v.1.4. - AutoLoad feature added ' v.1.3. - ClearAllBookmarks - bug fixed ' v.1.2. - ClearCurrentBookmark - added ' v.1.1 - ShowQuickBookmarks - added 'Copy contents of this file to the existing macro file 'OR add this file to list of macro files (Tools\Macro\Options>>\Loaded Files) 'Assign hotkey 'ALT+NUM 1' for QuickBookmark1 and so on 'Assign hotkey 'ALT+NUM/' for ShowQuickBookmarks() 'Assign hotkey 'ALT+NUM-' for ClearCurrentBookmark() 'SELECT text and press hotkey#n to DEFINE bookmark#n 'press hotkey#n to GOTO bookmark#n ' ALT+NUM 1 Sub QuickBookmark1() QuickBookmark 1 End Sub ' ALT+NUM 2 Sub QuickBookmark2() QuickBookmark 2 End Sub ' ALT+NUM 3 Sub QuickBookmark3() QuickBookmark 3 End Sub ' ALT+NUM 4 Sub QuickBookmark4() QuickBookmark 4 End Sub ' ALT+NUM 5 Sub QuickBookmark5() QuickBookmark 5 End Sub ' ALT+NUM 6 Sub QuickBookmark6() QuickBookmark 6 End Sub ' ALT+NUM 7 Sub QuickBookmark7() QuickBookmark 7 End Sub ' ALT+NUM 8 Sub QuickBookmark8() QuickBookmark 8 End Sub ' ALT+NUM 9 Sub QuickBookmark9() QuickBookmark 9 End Sub ' ALT+NUM 10 Sub QuickBookmark10() QuickBookmark 10 End Sub Dim sQuickBookmark_File(11) Dim sQuickBookmark_Short(11) Dim sQuickBookmark_Source(11) Dim nQuickBookmark_LocNum(11) Dim nQuickBookmark_Line(11) Dim QBookmarksLoaded Dim QBookmarksCancelAutoLoad 'function to define or go to bookmark Sub QuickBookmark(i) if QBookmarksLoaded=0 then LoadQuickBookmarks Set sel = ActiveDocument.Selection if (Len(sel.Text)) then SetBookMark(11) ClearBookMark(i) sQuickBookmark_File(i) = sQuickBookmark_File(11) sQuickBookmark_Short(i) = sQuickBookmark_Short(11) sQuickBookmark_Source(i) = sQuickBookmark_Source(11) nQuickBookmark_LocNum(i) = nQuickBookmark_LocNum(11) end if GoToBookMark(i) End Sub ' defines bookmark sub SetBookMark(i) Set sel = ActiveDocument.Selection line_text = Left(Trim(sel.Text),80) file = ActiveDocument.FullName line = sel.CurrentLine sel.SetBookmark sQuickBookmark_File(i) = file sQuickBookmark_Short(i) = ActiveDocument.Name if (Len(sel.Text) > 0) then sQuickBookmark_Source(i) = line_text current = GetCurrentBookMarkNum() nQuickBookmark_LocNum(i) =0 for n = 1 to 11 if sQuickBookmark_File(n) = file and nQuickBookmark_LocNum(n)>=current then nQuickBookmark_LocNum(n) = nQuickBookmark_LocNum(n)+1 end if next nQuickBookmark_LocNum(i) = current End Sub 'fuction to clear old bookmark with the same number sub ClearBookMark(i) if sQuickBookmark_File(i)="" then exit sub GoToBookMark(i) current = nQuickBookmark_LocNum(i) file = sQuickBookmark_File(i) ActiveDocument.Selection.ClearBookMark current = nQuickBookmark_LocNum(i) file = sQuickBookmark_File(i) for n = 1 to 11 if sQuickBookmark_File(n) = file and nQuickBookmark_LocNum(n)>current then nQuickBookmark_LocNum(n) = nQuickBookmark_LocNum(n)-1 end if next sQuickBookmark_File(i) = "" end sub ' goes to bookmark sub GoToBookMark(i) if sQuickBookmark_File(i)="" then exit sub Application.Documents.Open sQuickBookmark_File(i) if (NoBookMarksDefined(ActiveDocument)) then Application_DocumentOpen(ActiveDocument) set sel=ActiveDocument.Selection local_num = nQuickBookmark_LocNum(i) sel.StartOfDocument dsMove FOR l = 1 to local_num sel.NextBookMark Next nQuickBookmark_Line(i) = sel.CurrentLine end sub ' calculates number of current bookmark from the beginning of the file function GetCurrentBookMarkNum() set sel=ActiveDocument.Selection line = sel.CurrentLine sel.StartOfDocument dsMove FOR i=1 to 100 sel.NextBookMark if (sel.CurrentLine = line) then GetCurrentBookMarkNum = i: exit function next end function function NoBookmarksDefined(theDocument) theDocument.Selection.StartOfDocument dsMove NoBookmarksDefined = (theDocument.Selection.NextBookmark = false) end function ' Alt+NUM/ Sub ShowQuickBookmarks() if QBookmarksLoaded=0 then LoadQuickBookmarks text = +Chr(10) for i = 1 to 10 if (sQuickBookmark_File(i)<>"") then text = text +" #"+Cstr(i)+" : """+sQuickBookmark_Source(i)+""" "+Chr(9)+sQuickBookmark_Short(i) +","+Cstr(nQuickBookmark_Line(i))+ Chr(10) end if next res = MsgBox( text+Chr(10)+" Press 'No' to clear or reload all bookmarks "+Chr(10)+" Press 'Yes' to save bookmarks to file", vbYesNoCancel,"LIST OF QUICK BOOKMARKS" ) if res = vbNo then FOR each doc in Documents doc.ClearBookmarks next for i = 1 to 10 sQuickBookmark_File(i) = "" nQuickBookmark_Line(i) = 0 sQuickBookmark_Source(i) = "" next if MsgBox( "Load bookmarks from file? ", vbYesNo)=vbYes then LoadQuickBookmarks end if if res = vbYes then SaveQuickBookmarks end if end sub ' hot key - ALT NUM- sub ClearCurrentBookmark() file = ActiveDocument.FullName line = ActiveDocument.Selection.CurrentLine for i = 1 to 10 if sQuickBookmark_File(i) = file and nQuickBookmark_Line(i) = line then ClearBookmark(i) Exit sub end if next end sub 'loas bookmarks from file sub LoadQuickBookmarks() QBookmarksLoaded = 0 Set old = ActiveDocument.Selection old_line = old.CurrentLine On Error Resume Next file_name = "QuickBookmarks.txt" Documents.Open file_name, "Text" if Err.Number <> 0 or ActiveDocument.Name<>file_name then MsgBox "QuickBookmarks file does not exist or cannot be opened!" Exit Sub end if Set sel = ActiveDocument.Selection sel.StartOfDocument dsMove for i=1 to 10 sel.GotoLine i*3-2 sel.EndOfLine dsExtend sQuickBookmark_File(i) = sel.Text sel.GotoLine i*3-1 sel.EndOfLine dsExtend sQuickBookmark_Source(i) = sel.Text sel.GotoLine i*3 sel.EndOfLine dsExtend nQuickBookmark_Line(i) = sel.Text next ActiveDocument.Close for i=1 to 10 if sQuickBookmark_File(i)<>"" then Documents.Open sQuickBookmark_File(i) ActiveDocument.Selection.GotoLine nQuickBookmark_Line(i) SetBookMark(i) end if next old.GotoLine old_line QBookmarksLoaded = 1 end sub 'saves bookmarks to file sub SaveQuickBookmarks() On Error Resume Next file_name = "QuickBookmarks.txt" Documents.Open file_name, "Text" if Err.Number <> 0 then 'If not, make new empty document Documents.Add "Text" ActiveDocument.Save file_name else ActiveDocument.Selection.SelectAll ActiveDocument.Selection.BackSpace End If set sel = ActiveDocument.Selection for i = 1 to 10 sel.Text = sQuickBookmark_File(i) sel.NewLine sel.Text = sQuickBookmark_Source(i) sel.NewLine sel.Text = CStr(nQuickBookmark_Line(i)) sel.NewLine next ActiveDocument.Save sFullName, False ActiveDocument.Close End sub sub Application_DocumentOpen(theDocument) old_line = theDocument.Selection.CurrentLine if NoBookMarksDefined(theDocument)=false then exit sub if QBookmarksLoaded = 1 then cur_name = theDocument.FullName theDocument.ClearBookmarks for i=1 to 10 if sQuickBookmark_File(i)=cur_name then ActiveDocument.Selection.GotoLine nQuickBookmark_Line(i) ActiveDocument.Selection.SetBookmark end if next end if theDocument.Selection.GotoLine old_line end sub sub Application_WorkspaceClose() SaveQuickBookmarks end sub sub Application_WindowActivate(window) if QBookmarksCancelAutoLoad=1 then exit sub QBookmarksCancelAutoLoad =1 'if MsgBox("Do you want to load QuickBookmarks?",vbYesNo)=vbYes then LoadQuickBookmarks 'end if End sub