Macro to auto update bookmark dates

  • Thread starter dates, dates and more dates
  • Start date
D

dates, dates and more dates

Hi All,

I have created a template which uses bookmarks and fieldforms to get data
from our database. we are a school and we have students always starting on
mondays except for public holiday. here is my problem

below is a macro found at woody's (great website)
I have 2 bookmarks (E_ST_DATE) & (public holiday) but when the macro is ran
it seem to caculate before e_st_date is updated because I get a return of
31/12/1899 as my result

Sub AutoNew()
Selection.GoTo What:=wdGoToBookmark, Name:="publicholiday"
Selection.InsertAfter Format((E_ST_DATE + 1), "dd/mm/yyyy")
End Sub

What I want to achieve is e.g (e_st_date = 10/09/2007 then publicholiday =
11/09/2007) The trouble is thou e_st_date will always change and I just want
to add 1 to wat ever date that is.

Please help
 
D

Doug Robbins - Word MVP

You should use:

With ActiveDocument
.Bookmarks("publicholiday").Range.InsertBefore Format(DateAdd("d", 1,
..Bookmarks("E_ST_DATE").Range.Text), "dd/mm/yyyy")
End With

However, you can do it without a macro. See fellow MVP Macropod's
DateCalc.Zip item that you can download from another Fellow MVP Graham
Mayor's website at http://www.gmayor.com/downloads.htm
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"dates, dates and more dates"
 
D

dates, dates and more dates

Doug, Thank you for your response

I am looking into the datecalc document. However can I be pain,

The below macro looks good but I can not seem to make it work. Is it
possible to get the full macro (I think it is my copy and paste technique).

When I paste it doesn't like the ..bookmarks

Aaron



Aaron
 
D

Doug Robbins - Word MVP

The mail program has inserted a line break in second line of code. In that
below, I have inserted a Visual Basic line break character (space then
underscore) that should overcome the problem

With ActiveDocument
.Bookmarks("publicholiday").Range.InsertBefore Format(DateAdd("d", 1, _
..Bookmarks("E_ST_DATE").Range.Text), "dd/mm/yyyy")
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"dates, dates and more dates"
 
D

dates, dates and more dates

Hi Doug or anyone,

I am now just becoming annoying. I deleted all macros what I had on my
template and copied ad pasted the following ... it looks exactly like below

With ActiveDocument
..Bookmarks("publicholiday").Range.InsertBefore Format(DateAdd("d", 1, _
...Bookmarks("E_ST_DATE").Range.Text), "dd/mm/yyyy")
End With

However this says It is invalid. I am happy to send my template thru and get
a quote on getting it to work.

p.s I tried to use the datecal but it is not updateing from the bookmark so
I really want to get this macro to work.

Any assistance on this would be greatly appreciated.

Aaron
 
R

Russ

Aaron,
Doug's .bookmark line has to look to VBA as one whole line. The space with
underscore helps to break up long lines.
I can copy and paste what I have below into a subroutine with no problems.

You can use it to bump up the date. The bookmarks/data it refers to must
already exist in the document or you will get an error.

With ActiveDocument
..Bookmarks("publicholiday").Range.InsertBefore Format(DateAdd("d", 1, _
..Bookmarks("E_ST_DATE").Range.Text), "dd/mm/yyyy")
End With
 
D

dates, dates and more dates

Hi Russ,

I must be really stupid. I have copied and pasted what you said below but I
still get an error

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Invalid outside procedure
---------------------------
OK Help
---------------------------

and it highlights the words With ActiveDocument

You mentioned a subroutine?? Should I have something that goes with the code?

Aaron
 
R

Russ

Aaron,
Do you know how to create a macro?
You can name the subroutine with any name other than something that VBA
uses, unless you intentionally plan to intercept a VBA command.
No spaces or punctuation other than underscores allowed in a subroutine name
or a bookmark name. You can try what I have below. Remember I said the
bookmarks must already exist in the active document. Delete any double dots
or extra blank lines that may show up through the act of posting this
routine. There are no blank lines within the subroutine below.

Sub Move_Ahead_One_Day()
With ActiveDocument
..Bookmarks("publicholiday").Range.InsertBefore Format(DateAdd("d", 1, _
..Bookmarks("E_ST_DATE").Range.Text), "dd/mm/yyyy")
End With
End Sub
 

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