Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

create macro?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
n6trf - 12 Feb 2008 21:45 GMT
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

Signature

____________________________________
In Christ's matchless name
   ted      &    colleen
n6trf               kc6rue

Doug Robbins - Word MVP - 12 Feb 2008 23:40 GMT
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.

Signature

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

>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.
[quoted text clipped - 55 lines]
>
> What do i have to do to get the date ... in the doc not the header. TIA
n6trf - 14 Feb 2008 00:06 GMT
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.

> 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
[quoted text clipped - 68 lines]
>>
>> What do i have to do to get the date ... in the doc not the header. TIA
Doug Robbins - Word MVP - 14 Feb 2008 03:11 GMT
See the article "How can I prevent users from editing the header of a
document in Word 2000 or higher?" at:

http://www.word.mvps.org/FAQs/Customization/ProtectWord2000PlusHeader.htm

Signature

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

> 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
[quoted text clipped - 75 lines]
>>>
>>> What do i have to do to get the date ... in the doc not the header. TIA
Graham Mayor - 14 Feb 2008 08:35 GMT
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

Signature

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

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

> 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
[quoted text clipped - 84 lines]
>>>    ted      &    colleen
>>> n6trf               kc6rue
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.