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 2008

Tip: Looking for answers? Try searching our database.

If selection is in a table or in the docbody

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dylan - 30 May 2008 14:35 GMT
I have a calendar that inputs the selected date into a formfield in a table.
I want to add another field outside of the table and amend the VBA to apply
the date.

How do I make VBA recognise whether the formfield is in a table or just in
the body of the document? I tried - If rng.Tables(1).Columns.Count > 1
Then... but it doesn't work. I'm not an expert as you can see.

Dim rng As Range
Set rng = Selection.Range
On Error Resume Next

'Unprotect
If ActiveDocument.ProtectionType <> wdNoProtection Then
 bProtected = True
 ActiveDocument.Unprotect Password:=""
End If

If rng.Tables(1).Columns.Count > 1 Then
With rng.Cells(1)
       .Range.FormFields(1).Result = Format(ctrlCal.Value, "dd MMM yyyy")
End With
Else: ActiveDocument.FormFields("pfield1").Result = Format(ctrlCal.Value,
"dd MMM yyyy")
End If
Unload Me...

regards
Dylan
Graham Mayor - 30 May 2008 14:53 GMT
Simply address the form field by bookmark name. It doesn't then matter where
it is.
See the final example at http://www.gmayor.com/popup_calendar.htm

Signature

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

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

> I have a calendar that inputs the selected date into a formfield in a
> table. I want to add another field outside of the table and amend the
[quoted text clipped - 26 lines]
> regards
> Dylan
dd - 30 May 2008 23:40 GMT
Thanks Graham, problem solved.

popup_calendar.htm was a big help too.

Regards
Dylan

> Simply address the form field by bookmark name. It doesn't then matter
> where it is.
[quoted text clipped - 30 lines]
>> regards
>> Dylan
 
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.