How do I enter a field with the current time + six hours?

1 view
Skip to first unread message

roursler

unread,
Jan 15, 2010, 11:16:04 PM1/15/10
to
I am making a macro for printing medication labels. I need to have an
expiration time on the label and would like it to be the current time + 6
hours. How can I structure the field to do this?

Doug Robbins - Word MVP

unread,
Jan 15, 2010, 11:31:51 PM1/15/10
to

I would put a { docvariable exptime } field in the label where you want the
time to appear and in your code use

With ActiveDocument
.Variables("exptime").Value = Format(DateAdd("h", 6, Now), "h:mm am/pm")
.Range.Fields.Update
.PrintOut
End With

You must use Ctrl+F9 to insert the field delimiters around the docvariable
field and use Alt+F9 to toggle off their display

--
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, originally posted via msnews.microsoft.com

"roursler" <rour...@discussions.microsoft.com> wrote in message
news:77CA2157-36DE-4769...@microsoft.com...

Karl E. Peterson

unread,
Jan 19, 2010, 7:26:42 PM1/19/10
to
Doug Robbins - Word MVP explained on 1/15/2010 :

>> would like it to be the current time + 6 hours.
>
> Format(DateAdd("h", 6, Now), "h:mm am/pm")

Not that there's anything wrong with that approach. It's probably the
most readable answer there is. Just wanted to kick in another method,
for sake of having all options out there.

Background: Date variables are really Doubles in drag. The day is
stored in the whole portion, and the time in the fractional part.

So, to add 6 hours, one need only add a quarter of a day:

Format(Now + 0.25, "h:mm am/pm")

Might be useful, for more calculation intensive operations...

--
.NET: It's About Trust!
http://vfred.mvps.org


Doug Robbins - Word MVP

unread,
Jan 20, 2010, 3:44:10 AM1/20/10
to

Thanks, Karl. Good to know.

--
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, originally posted via msnews.microsoft.com

"Karl E. Peterson" <ka...@exmvps.org> wrote in message
news:eNHu#cWmKH...@TK2MSFTNGP04.phx.gbl...

redtwotwo

unread,
Jan 26, 2010, 6:39:47 PM1/26/10
to
Hi. I am trying something similar as this but I would like to create a
sheet of labels which has the date + 15 days. How would you suggest
implementing this? There are many labels per page, do I have to create
many different variables and allow the vba to set each one or is there
an easier way?

I have used vba in excel but this is my first venture for word. I
would be grateful for help in this area.

Thanks
Heather

On Jan 20, 2:44 am, "Doug Robbins - Word MVP"


<d...@REMOVECAPSmvps.org> wrote:
> Thanks, Karl.  Good to know.
>
> --
> 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, originally posted via msnews.microsoft.com
>

> "Karl E. Peterson" <k...@exmvps.org> wrote in messagenews:eNHu#cWmKH...@TK2MSFTNGP04.phx.gbl...

Graham Mayor

unread,
Jan 27, 2010, 2:29:20 AM1/27/10
to
See http://www.gmayor.com/insert_a_date_other_than_today.htm and in
particular the link to http://www.gmayor.com/downloads.htm#Third_party

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"redtwotwo" <bills...@gmail.com> wrote in message
news:d3a8c75e-acb2-4579...@l11g2000yqb.googlegroups.com...

Doug Robbins - Word MVP

unread,
Jan 30, 2010, 1:13:23 AM1/30/10
to

In the Labels dialog in word, having selected the type of label that you are
using and with the selection in the Address area of the dialog, Press
Ctrl+F9 to insert a pair of field delimiters { } and inside them type

{ DOCVARIABLE varDate }

The select the Full page of the same label radio button and then click on
New Document.

Then with that document as the active document, run a macro containing the
following code

With ActiveDocument
.Variables("varDate").Value = Format(DateAdd("d", 15, Now), "dd mmmm
yyyy" )
.Range.Fields.Update
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, originally posted via msnews.microsoft.com

"redtwotwo" <bills...@gmail.com> wrote in message
news:d3a8c75e-acb2-4579...@l11g2000yqb.googlegroups.com...

Reply all
Reply to author
Forward
0 new messages