I have a table with 2 rows/3 columns in the header of the first page. Unfortunately, it just doesn't go to the last cell. I need to delete whatever is in the cell and copy from autotext into the last cell. It works fine for 1st cell. It always jumps to cell (2, 2) and not (2, 3). Any ideas? Thanks.
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With ActiveDocument.Sections(1)
' Update the FI logo ***** WORKS FINE *****
.Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(1, 1).Select
Selection.Range.Delete
Selection.Collapse Direction:=wdCollapseStart
ActiveDocument.AttachedTemplate.AutoTextEntries(GetColourName(iRCIndex)).Insert _
Where:=Selection.Range, _
RichText:=True
' Update the coloured triangle ***** WORKS FINE *****
.Headers(wdHeaderFooterFirstPage).Shapes("CT1").Select
Selection.ShapeRange.Fill.ForeColor = lngColour
' update the logo numbre 2 ***** DOESN'T WORK ***** Goes into 2nd row 2nd coloumn *****
.Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(2, 3).Select
Selection.Range.Delete
Selection.Collapse Direction:=wdCollapseStart
ActiveDocument.AttachedTemplate.AutoTextEntries(GetColourNameAGAIN(iRCIndex)).Insert _
Where:=Selection.Range, _
RichText:=True
End With
HansV wrote:I can't explain the behaviour that you describe. If you wish, you could attach a sample document (remove sensitive/proprietary information).
Thanks Hans.
It was difficult to attach a sample document - it's all embeded code. Anyway, I reselected the cell after deleting the contenet of it - just for the heck of it & it worked. Word is really baffling. I have spent so many days just trying to figure out things and it turns out to be totally stupid.
Sub Test()
Dim Rng As Range, iRCIndex As Long
With ActiveDocument
' Update the FI logo
Set Rng = .Sections(1).Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(1, 1).Range
Rng.End = Rng.End - 1
Rng.Text = vbNullString
.AttachedTemplate.AutoTextEntries(GetColourName(iRCIndex)).Insert Where:=Rng, RichText:=True
' update the logo number 2
Set Rng = .Sections(1).Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(2, 3).Range
Rng.End = Rng.End - 1
Rng.Text = vbNullString
.AttachedTemplate.AutoTextEntries(GetColourNameAGAIN(iRCIndex)).Insert Where:=Rng, RichText:=True
' Update the coloured triangle
.Headers(wdHeaderFooterFirstPage).Shapes("CT1").ShapeRange.Fill.ForeColor = lngColour
End With
Set Rng = Nothing
End Sub
Sub Test()
Dim Rng As Range, iRCIndex As Long
With ActiveDocument
' Update the FI logo
Set Rng = .Sections(1).Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(1, 1).Range
Rng.End = Rng.End - 1
Rng.Text = vbNullString
.AttachedTemplate.AutoTextEntries(GetColourName(iRCIndex)).Insert Where:=Rng, RichText:=True
' update the logo number 2
Set Rng = .Sections(1).Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(2, 3).Range
Rng.End = Rng.End - 1
Rng.Text = vbNullString
.AttachedTemplate.AutoTextEntries(GetColourNameAGAIN(iRCIndex)).Insert Where:=Rng, RichText:=True
' Update the coloured triangle
.Headers(wdHeaderFooterFirstPage).Shapes("CT1").ShapeRange.Fill.ForeColor = lngColour
End With
Set Rng = Nothing
End Sub
Hi Paul (Macropod)
That is just wonderful bit of code. Never realised I could use just the range - have always used selection (well one always learns something new). THANK YOU. It is so FAST - :0)
But, one slight problem. After updating the logos and changing the colour, the logos become rectangular square with X in it. See image. Any idea why since it looked fine when I used selection. Thanks.
x4images.png
You do not have the required permissions to view the files attached to this post.
The RED "X" means that the image can not be found at the location linked in the document, check the links to see if the images are where they should be?
I am so far behind, I think I am First
Genealogy....confusing the dead and annoying the living