return to where it was

J

justamailman

Hi, i have a macro that goes to find a text and copy it but would like to
come back at the last prompt i was at first.
 
H

Helmut Weber

Hi,
just one of many ways:
define where you are, like:
dim rHere as range ' you are here
set rHere = selection.range
' do what you like
rHere.select ' goback

But, of course, this can only work,
if you haven't deleted rHere in the meantime,
in a way, or changed it by deleting text before it.
Theoretically, you could change or delete all
of the doc except the end of doc mark (the last paragraph).
So the only two safe points you can use for a return,
is end of doc in a way, or start of doc,
which is the same, if all of doc was deleted. ;-)

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
J

justamailman

thanks. Helmut,is there a place where to learn thoses dim things and how do
we see the different choice available as we build using f8 if that is possible
 
H

Helmut Weber

Hi,

hm... kind of difficult to explain.
probably in any book for VBA-beginners.
Go to the top of the code in the VBA-Editor, insert
Option Explicit
which tells VBA, to warn you, if a variable
wasn't declared. If you don't know about variables,
I really don't know where to start.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
G

Greg Maxey

Maybe you coul adapt the following to suit your needs. I use it to insert a
bookmark at the insertion point, go off and do a find, and then return to
and delete the bookmark.

Sub GoBack()
Dim dlgFind As Dialog
Set dlgFind = Dialogs(wdDialogEditFind)

With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="IPMark"
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
With dlgFind
.Find = ""
.Show
End With
Selection.GoTo What:=wdGoToBookmark, Name:="IPMark"
ActiveDocument.Bookmarks("IPMark").Delete
End Sub
 
J

justamailman

sorry option explicit not available to me my WORD in 97 version, may be that
is why
just a learner here but find it really interesting . your help is precious
Helmut
 
H

Helmut Weber

Hi,
by the way, in my Word 97 SR-2
there is "option explicit".

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
J

justamailman

I have only sr1 may be that is why unless I am not looking at the right place
 
J

justamailman

found that I had download office sr2 before but it still show version sr1 in
Word, dont understand that. Dont know what to do
 
J

justamailman

yes now having SR2 but still no ootion explicit under insert menu. Why?sorry
Helmut
 
H

Helmut Weber

Hi,
yes now having SR2 but still no ootion explicit under insert menu. Why?
you don't insert "Option Explicit",
you just type it at the top of a module [ctrl pos1]
Probably in English (common), (declarations).
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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