Calculated Timing variable displayed on each page

D

DBDeveloper

Hi,
I need help with what approach I should take to automatically change a
value on each page with a command.

I have a training document that is expected to take, for example, an
instructor about 8 minutes per page to present.
I want the "guidline" value shown on each page to be based on a start
time maybe on the first page and then calculate the value for each
suceeding page based on the page number. i.e., Page 6 value should be
the StartTime+(8sec*PageNumber). StartTime can be manually adjusted
rather than reading computer time.
I'm not sure how to state the question nor how to automate a value for
each page based on the manual StartTime variable.
I created a text box formatted to float in the footer area which I can
manually change the value for each page.
Ideally this calculated time value would appear in the header or
footer "area" but not necessarily be a part of the header or footer
which want to remain the same for the document section.

I'm having trouble defining the search question to find relevant
information about the issue.

Thanks for any suggestions,
Dennis
 
D

Doug Robbins - Word MVP

if you insert the following field construction { DOCVARIABLE "Page{ Page } }
in the header or footer of the document using Ctrl+F9 to insert each pair of
field delimiters, and you run a macro containing the following code when
starting the presentation, it will display the current time on the first
page and that time incremented by 8 minutes on each subsequent page:

Dim i As Long
With ActiveDocument
For i = 1 To .BuiltInDocumentProperties(wdPropertyPages)
.Variables("Page" & i).Value = Format(DateAdd("n" 8 * (i - 1), Now),
"hh:nn")
.PrintPreview
.ClosePrintPreview
Next i
End With

This need not affect the rest of your header or footer information.

I would suggest that it might be best to put it in the footer and use

Dim i As Long
With ActiveDocument
For i = 1 To .BuiltInDocumentProperties(wdPropertyPages)
.Variables("Page" & i).Value = Format(DateAdd("s", 8 * i, Now),
"hh:nn:ss")
.PrintPreview
.ClosePrintPreview
Next i
End With

So that it would show the present the time at which he should be finished
with the current page.

Or, if you were going to be printing out the document and you want to be
able to enter a scheduled start time, use

Dim i As Long
Dim starttime As Variant
starttime = InputBox("Enter the Start Time in the following format hh:mm.")
With ActiveDocument
For i = 1 To .BuiltInDocumentProperties(wdPropertyPages)
.Variables("Page" & i).Value = Format(DateAdd("n", 8 * (i - 1),
starttime), "hh:nn")
.PrintPreview
.ClosePrintPreview
Next i
End With
 
D

DBDeveloper

if you insert the following field construction { DOCVARIABLE "Page{ Page } }
in the header or footer of the document using Ctrl+F9 to insert each pairof
field delimiters, and you run a macro containing the following code when
starting the presentation, it will display the current time on the first
page and that time incremented by 8 minutes on each subsequent page:

Thanks Doug that helps a lot.
Now I have the next step to resolve.
These are day long classes so have to resolve breaks, practice time,
lunch and such.

I have a spreadsheet where I calculate a 15min AM break around 10AM,
an hour before lunch for a hands-on practice period, a 45 min lunch, a
15min PM break around 2PM, a 1 hour HandsOn practice begining at about
3:30.
It's set up to just put in the start time variable, a page time
variable and calculate the rest.

Currently I have a locked frame on each page that I manually edit
after completing the document. Start times vary quite a bit and due
to number of pages and content also the page time.

I had tried to link using the page number to my SS (which has a pageNo
field) but I failed miserably in the attempt though I learned a lot in
the process about what doesn't work.

Is there any way to use your samples to obtain the pageNo and then
link to my SS and one field right (PgInstTime) to get the calculated
date (which includes the timeout variables)?

This would seem a common need for many instructional manual developers
though I couldn't find anything in the forums. Difficult to frame the
question actually.

Thanks for any help and feedback,
Dennis
 
D

Doug Robbins - Word MVP

The following code will access a range to which the name Times is assigned
in an Excel Workbook (you will need to change the filepath and name in the
Set xlbook = xlapp.Workbooks.Open("C:\Users\Doug\Documents\times.xls")
command and create document variables with the values contained in second
through the last cell in the range.

Note, you will need to use the =Text() function in range in Excel to convert
your calculated values to Text in the format that you want the times to be
displayed ("hh:mm")


Dim xlapp As Object
Dim xlbook As Object
Dim Timearray As Variant
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
bstartApp = True
Set xlapp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlbook = xlapp.Workbooks.Open("C:\Users\Doug\Documents\times.xls")
Timearray = xlbook.Names("times").RefersToRange.Value
xlbook.Close SaveChanges:=False
If bstartApp = True Then
xlapp.Quit
End If
Set xlapp = Nothing
Set xlbook = Nothing
With ActiveDocument
For i = 2 To UBound(Timearray)
.Variables("Page" & i - 1).Value = Timearray(i, 1)
Next i
.PrintPreview
.ClosePrintPreview
End With
 

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