Selecting a table in a footer

R

Roderick O'Regan

I'm trying to adapt the following code to find out if there is a table
in any of the footers:

kJunk = ActiveDocument.Sections(1).Footers(1).Range.StoryType
'Iterate through all story types in the current document
For Each kStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
On Error Resume Next
Select Case kStory.StoryType
Case wdEvenPagesFooterStory, wdFirstPageFooterStory,
wdPrimaryFooterStory
*
* Pseudo-code: If there are any tables in this story then select the
third cell in the first row
*
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set kStory = kStory.NextStoryRange
Loop Until kStory Is Nothing
Next

Can anyone help with this please?

Roderick
 
J

Jonathan West

Inline...

Roderick O'Regan said:
I'm trying to adapt the following code to find out if there is a table
in any of the footers:

kJunk = ActiveDocument.Sections(1).Footers(1).Range.StoryType
'Iterate through all story types in the current document
For Each kStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
On Error Resume Next
Select Case kStory.StoryType
Case wdEvenPagesFooterStory, wdFirstPageFooterStory,
wdPrimaryFooterStory
*
* Pseudo-code: If there are any tables in this story then select the
third cell in the first row

If kStory.Tables.Count > 0 Then
kStory.Tables(1).Cell(1, 3).Range.Select
End If

*
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set kStory = kStory.NextStoryRange
Loop Until kStory Is Nothing
Next

Can anyone help with this please?

Roderick


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
R

Roderick O'Regan

Thanks Jonathan.

It works just great.

I replaced the .Range.Select with
..Range.Delete
because it was going into split screen Normal view.

I then tried to be clever and wrote the instruction:
ActiveDocument.AttachedTemplate.AutoTextEntries("B&WSmallLogo").Insert
_
Where:=Selection.Range, RichText:=True

....to put a small logo in the now empty cell. Of course, this
wouldn't work as one moment I'm dealing with Ranges and in the other
with Selection (How often do I read here "use Ranges not
Selections!").

What is the keyword, please, that will satisfy the Where:= above which
will use the range instead of the selection?

Thanks again.

Roderick
 
J

Jonathan West

Roderick O'Regan said:
Thanks Jonathan.

It works just great.

I replaced the .Range.Select with
.Range.Delete
because it was going into split screen Normal view.

I then tried to be clever and wrote the instruction:
ActiveDocument.AttachedTemplate.AutoTextEntries("B&WSmallLogo").Insert
_
Where:=Selection.Range, RichText:=True

...to put a small logo in the now empty cell. Of course, this
wouldn't work as one moment I'm dealing with Ranges and in the other
with Selection (How often do I read here "use Ranges not
Selections!").

What is the keyword, please, that will satisfy the Where:= above which
will use the range instead of the selection?

Dim myRange as Range
If kStory.Tables.Count > 0 Then
Set myRange = kStory.Tables(1).Cell(1, 3).Range
myRange.Collapse direction:=wdCollapseStart
ActiveDocument.AttachedTemplate.AutoTextEntries("B&WSmallLogo").Insert _
Where:=myRange, RichText:=True
End If

I'd have given you that before if you had said what you *really* wanted :)

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
R

Roderick O'Regan

Thanks very much, Jonathan.

I take your point of what I *really* wanted. However, I just wanted
the basic information and then see if I could develop that myself to
the end result.

I failed dismally! Hence the second part.

Roderick
 

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