Run Macro/Macro at specific location

G

Guest

I asked for help on 2/01/04 for updating dates, (thanks to all that responded), I was refered t
http://www.gmayor.com/insert_a_date_other_than_today.htm, I downloaded the macro InsertFutureDate
Inserted in doc and assigned command button the run it on toolbar. This works great, but i have to insert (3) differen
dates at (3) different locations. Trying to automate this i open doc and recorded new macro (assigning button to toolbar)where i arrowed down to the first insert point, highlignted the date, deleted, and ran InsertFutureDate macro, I continued this on all (3) locations and stopped macro. I ran new macro and it worked like i wanted it to the first time
I ran it a second time and it seems to be starting at a different location, because it did what it was suppose t
but it deleted the wrong area and inserted at the wrong locations
Any help on this would be greatly appreciate
Jimmy
 
G

Graham Mayor

The macro was never intended for such complexity, and the reason that it is
not working as you planned is because you have not set bookmarks at the
required locations nor asked the application to move to the new location
before writing in the data.
At its most basic, you need three bookmarks in the document/template at the
the required positions eg Date1, Date2 & Date3
The following will add 14, 28 and 56 days to the three positions. Change to
suit your requirements.

Sub ThreeDates()
With Selection
.GoTo What:=wdGoToBookmark, Name:="Date1"
.InsertBefore Format((Date + 14), "d MMMM yyyy")
.GoTo What:=wdGoToBookmark, Name:="Date2"
.InsertBefore Format((Date + 28), "d MMMM yyyy")
.GoTo What:=wdGoToBookmark, Name:="Date3"
.InsertBefore Format((Date + 56), "d MMMM yyyy")
End With
End Sub

Or you could do it with complex fields -
http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=wrd&Number=249902

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 
G

Guest

----- Graham Mayor wrote: ----

The macro was never intended for such complexity, and the reason that it i
not working as you planned is because you have not set bookmarks at th
required locations nor asked the application to move to the new locatio
before writing in the data
At its most basic, you need three bookmarks in the document/template at th
the required positions eg Date1, Date2 & Date
The following will add 14, 28 and 56 days to the three positions. Change t
suit your requirements

Sub ThreeDates(
With Selectio
.GoTo What:=wdGoToBookmark, Name:="Date1
.InsertBefore Format((Date + 14), "d MMMM yyyy"
.GoTo What:=wdGoToBookmark, Name:="Date2
.InsertBefore Format((Date + 28), "d MMMM yyyy"
.GoTo What:=wdGoToBookmark, Name:="Date3
.InsertBefore Format((Date + 56), "d MMMM yyyy"
End Wit
End Su

Or you could do it with complex fields
http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=wrd&Number=24990

--
<>><><<>><<><>><><<><>><<>><><<
Graham Mayor - Word MV
E-mail (e-mail address removed)
Web site www.gmayor.co
Word MVP web site www.mvps.org/wor
<>><><<>><<><>><><<><>><<>><><<


Jimmy wrote
I asked for help on 2/01/04 for updating dates, (thanks to all tha
responded), I was refered t
http://www.gmayor.com/insert_a_date_other_than_today.htm,
downloaded the macro InsertFutureDate
Inserted in doc and assigned command button the run it on toolbar
This works great, but i have to insert (3) differen
dates at (3) different locations. Trying to automate this i open do
and recorded new macro (assigning button to toolbar)where i arrowe
down to the first insert point, highlignted the date, deleted, an
ran InsertFutureDate macro, I continued this on all (3) locations an
stopped macro. I ran new macro and it worked like i wanted it to th
first time. I ran it a second time and it seems to be starting at
different location, because it did what it was suppose t
but it deleted the wrong area and inserted at the wrong locations
Any help on this would be greatly appreciate
Jimm


Mr. Mayor
Thank you for responding and the solutio
I had previously tried something like this with the record macro after setting bookmarks with go to bookmark, then ru
the InsertFutureDate Sub, but i guess it wasn't letting it stop for the input box so it would have an input variable
Below is the way I've ended up doing it. It was great, I can just go in an edit the days as needed if the occasion arises
Sub DeleteDates(

' DeleteDates Macr
' Macro recorded 2/5/2004 by jimmy dillar

Selection.GoTo What:=wdGoToBookmark, Name:="date_1
With ActiveDocument.Bookmark
.DefaultSorting = wdSortByLocatio
.ShowHidden = Fals
End Wit
Selection.MoveRight Unit:=wdCharacter, Count:=16, Extend:=wdExten
Selection.Delete Unit:=wdCharacter, Count:=
Selection.GoTo What:=wdGoToBookmark, Name:="date_2
With ActiveDocument.Bookmark
.DefaultSorting = wdSortByLocatio
.ShowHidden = Fals
End Wit
Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExten
Selection.Delete Unit:=wdCharacter, Count:=
Selection.GoTo What:=wdGoToBookmark, Name:="date_3
With ActiveDocument.Bookmark
.DefaultSorting = wdSortByLocatio
.ShowHidden = Fals
End Wit
Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExten
Selection.Delete Unit:=wdCharacter, Count:=
Selection.GoTo What:=wdGoToBookmark, Name:="date_1
With ActiveDocument.Bookmark
.DefaultSorting = wdSortByLocatio
.ShowHidden = Fals
End Wit
End Su
___________________
Sub ThreeDates(

' ThreeDates Macr
' Macro created 2/6/2004 by Graham Mayo

With Selectio
.GoTo What:=wdGoToBookmark, Name:="Date_1
.InsertBefore Format((Date + 0), "MMMM d, yyyy")
.GoTo What:=wdGoToBookmark, Name:="Date_2"
.InsertBefore Format((Date + 90), "MMMM d, yyyy")
.GoTo What:=wdGoToBookmark, Name:="Date_3"
.InsertBefore Format((Date + 91), "MMMM d, yyyy")
.GoTo What:=wdGoToBookmark, Name:="Est_1"
End With
End Sub

Again Thanks for the help
Jimmy
 

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