If selection is in a table or in the docbody

D

Dylan

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
 

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

Top