create macro?

N

n6trf

I created a macro by going into the header then setting tabs & entering the
data for the heading. @ that point I clicked on view & then header/footer.
That took me back to the document, I center justified & inserted the date,
left justified & inserted a couple of enters. When I executed the macro the
date & enters were placed in the header????

This is the macro

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2008-02-12 by ted medin
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(1), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(1.25), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(3), _
Alignment:=wdAlignTabCenter, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(3.6), _
Alignment:=wdAlignTabCenter, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(4.2), _
Alignment:=wdAlignTabCenter, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(4.6), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.TypeText Text:="Date" & vbTab & "Mem#" & vbTab & "Name" &
vbTab _
& "Total" & vbTab & "Deduct" & vbTab & "Nonded" & vbTab & "Items"
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:=
_
True, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.TypeParagraph
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End Sub

What do i have to do to get the date ... in the doc not the header. TIA
 
D

Doug Robbins - Word MVP

The macro recorder is not suitable for this task. In fact using a macro for
it is probably not the best thing to do either. If it is something that you
need to do often enough to think that a macro is the way to do it, then you
should really create a template with the header setup the way that you want
it and a { CREATEDATE } field in the body of the document where you want it.
Then when you need a new document (on which you would have used the macro)
you would select New from the File menu and select the template to which I
suggest you create above.

--
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
 
N

n6trf

Don't think that will work. The doc is a log of a years activity (not much
daily activity) every day when the log is brought up we need to insert the
date @ the end & reestablish the header & tabs. Amazing how operators can
foul those thing up in ways I cant figure out.
 
G

Graham Mayor

The following macro saved in the document template (hopefully not
normal.dot) will automatically insert the date at the end of the document
in whatever format you want (by changing the formatting switches) whenever
the document is opened. It adds that date to a bookmark and updates the
header, which should contain a REF field {Ref LogDate \*Charformat} in place
of the date in your header. The user then has no need to change the header
or update the fields.

The obvious problem would be if the document was created from normal.dot, in
which case rename the macro to (say) LogDate and provide a toolbar button to
insert the date - or attach a different template to which users have access,
based on normal.dot but containing the automacro. I lean to the button
approach, though it relies on users to actually use it.

http://www.gmayor.com/installing_macro.htm

Sub AutoOpen()
Dim sDate As String
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter

sDate = Format(Date, "d" & _
Chr(160) & "MMMM" & Chr(160) & "yyyy")
With Selection
.EndKey
.TypeParagraph
.InsertAfter sDate
End With
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, name:="LogDate"
End With
Selection.EndKey

For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader
Next oSection
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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

Similar Threads

Watermark macro 3
Macro to fix header 0
Bullet Styles Macro 0
Tab stop weirdness 8
Bookmark problem 0
Please help!!! No replies - Posting query again 0
Macro error 5941 1
If Then Else Statement 3

Top