Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Thu, 7 Feb 2008 09:03:44 -0500,    group: microsoft.public.word.vba.beginners        back       


Date Adjustments and Document Editing   
Hello all. I am having a little bit of trouble with MS Word 2003. I have a 
document for work that requires consecutive dates in it for a week. I would 
like to be able to enter the first date in the first field and Word 
automatically adjust the dates for the next six fields. Is this possible?

Also, I know it's probably off topic, but is it possible to enter text into 
a document and not affect the original text?
date: Thu, 7 Feb 2008 09:03:44 -0500   author:   Donald

Re: Date Adjustments and Document Editing   
It is certainly possible, but complex to do with fields see 
http://www.gmayor.com/insert_a_date_other_than_today.htm and especially the 
linked document from Macropod.

If these are form fields it might be simpler to do the job with a macro run 
on exit from the first date field eg Text1
This will fill Texts2 to 7 with dates each incremented by one. Ensure that 
Texts2 to 7 have the fill-in enabled property unchecked.

Sub AddaWeek()
Dim sDate As Date
Dim Count As Integer
Dim i As Long
Count = 1
For i = 2 To 7
    sDate = ActiveDocument.FormFields("Text1").Result
    sDate = Format((sDate + Count), "dd/MM/yyyy")
    ActiveDocument.FormFields("Text" & i).Result = sDate
    Count = Count + 1
Next i
End Sub




Donald wrote:
> Hello all. I am having a little bit of trouble with MS Word 2003. I
> have a document for work that requires consecutive dates in it for a
> week. I would like to be able to enter the first date in the first
> field and Word automatically adjust the dates for the next six
> fields. Is this possible?
> Also, I know it's probably off topic, but is it possible to enter
> text into a document and not affect the original text?
date: Thu, 7 Feb 2008 17:28:46 +0200   author:   Graham Mayor

Re: Date Adjustments and Document Editing   
Ok, I copy and pasted the code to the vbeditor. I set the first text field 
to run the addaweek module on exit and unchecked the Enable fill in on the 
other fields.

When I lock the document and enter a date into the first field I get this : 
RUN TIME ERROR '5941' THE REQUESTED MEMBER DOES NOT EXITS.

I debug and the line: sDate = ActiveDocument.FormFields("Text1").Result is 
highlighted

Where did I screw-up at?


And do you think that there is a way I can enter text onto a blank line w/o 
changing the line itself, only adding text?
date: Fri, 8 Feb 2008 08:57:12 -0500   author:   Donald

Re: Date Adjustments and Document Editing   
The error suggests that you don't have a Text1 form field containing the 
date you wish to add to.
The macro works on the premise that you have seven form fields named Text1 
to Text7 and that Text1 has a date entered into it.
The macro would also benefit from an extra line to ensure that the cursor 
moves to the next free field when you tab out of Text1

Sub AddaWeek()
Dim sDate As Date
Dim Count As Integer
Dim i As Long
Count = 1
For i = 2 To 7
    sDate = ActiveDocument.FormFields("Text1").Result
    sDate = Format((sDate + Count), "dd/MM/yyyy")
    With ActiveDocument.FormFields("Text" & i)
        .Result = sDate
        .Enabled = False
    End With
    Count = Count + 1
Next i
End Sub
-- 
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

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

Donald wrote:
> Ok, I copy and pasted the code to the vbeditor. I set the first text
> field to run the addaweek module on exit and unchecked the Enable
> fill in on the other fields.
>
> When I lock the document and enter a date into the first field I get
> this : RUN TIME ERROR '5941' THE REQUESTED MEMBER DOES NOT EXITS.
>
> I debug and the line: sDate =
> ActiveDocument.FormFields("Text1").Result is highlighted
>
> Where did I screw-up at?
>
>
> And do you think that there is a way I can enter text onto a blank
> line w/o changing the line itself, only adding text?
date: Fri, 8 Feb 2008 16:53:10 +0200   author:   Graham Mayor

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us