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 / May 2006

Tip: Looking for answers? Try searching our database.

Inserting Date into table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MarkN - 15 May 2006 02:50 GMT
Hello,

I am new to Word VBA and would like some help with a part of a macro. I need
the code to check whether the first cell of the first table in the document
is empty and if it is empty, enter the current date.
Signature

Thanks in advance,
MarkN

Greg Maxey - 15 May 2006 03:01 GMT
Here is one way:

Sub ScratchMacro()
If Len(ActiveDocument.Tables(1).Cell(1, 1).Range.Text) = 2 Then
 ActiveDocument.Tables(1).Cell(1, 1).Range.Text = Date
End If
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hello,
>
> I am new to Word VBA and would like some help with a part of a macro.
> I need the code to check whether the first cell of the first table in
> the document is empty and if it is empty, enter the current date.
MarkN - 16 May 2006 03:45 GMT
Thanks Greg,

Could I ask why the Len function =2 is used as the test in your IF function?
Signature

Thanks again,
MarkN

> Here is one way:
>
[quoted text clipped - 9 lines]
> > I need the code to check whether the first cell of the first table in
> > the document is empty and if it is empty, enter the current date.
Greg Maxey - 16 May 2006 03:57 GMT
Yes,

The end of cell marker in and empty cell takes up 2 characters.  I wouldn't
swear in a court of law, but I am pretty sure it is chr(13) & chr(7).

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Thanks Greg,
>
[quoted text clipped - 21 lines]
>>> table in the document is empty and if it is empty, enter the
>>> current date.
Greg Maxey - 16 May 2006 04:14 GMT
Now that I have been duly sworn ,  it is chr(13) and chr(7).  Select an
empty cell and run the following code:

Sub Test()
MsgBox Asc(Selection.Text) _
 & " and " & Asc(Right(Selection.Text, 1))
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Thanks Greg,
>
[quoted text clipped - 21 lines]
>>> table in the document is empty and if it is empty, enter the
>>> current date.
 
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.