cell selection fails for some reason

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

cell selection fails for some reason

Post by Robie »

Hi

Windows 7/Word 2003

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.

Code: Select all

    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

User avatar
HansV
Administrator
Posts: 78501
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: cell selection fails for some reason

Post by HansV »

Do you have split or merged cells in the table?

With a "plain" 2x3 table I cannot reproduce the error (I'm using Word 2010 on Windows 7) - the last cell of the table is duly selected.
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: cell selection fails for some reason

Post by Robie »

HansV wrote:Do you have split or merged cells in the table?

With a "plain" 2x3 table I cannot reproduce the error (I'm using Word 2010 on Windows 7) - the last cell of the table is duly selected.
No merged cells. Simple 2x3 table.

User avatar
HansV
Administrator
Posts: 78501
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: cell selection fails for some reason

Post by HansV »

I can't explain the behaviour that you describe. If you wish, you could attach a sample document (remove sensitive/proprietary information).
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: cell selection fails for some reason

Post by Robie »

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.

Code: Select all

        
        ' update the Fidessa logo
        .Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(2, 3).Select
        Selection.Range.Delete
        .Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(2, 3).Select
        Selection.Collapse Direction:=wdCollapseStart
        ActiveDocument.AttachedTemplate.AutoTextEntries(GetColourNameAGAIN(iRCIndex)).Insert _
                                                                                      Where:=Selection.Range, _
                                                                                      RichText:=True

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: cell selection fails for some reason

Post by macropod »

Hi robie,

Using selections is really inefficient. Try something along the lines of:

Code: Select all

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
Paul Edstein
[Fmr MS MVP - Word]

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: cell selection fails for some reason

Post by Robie »

macropod wrote:Hi robie,

Using selections is really inefficient. Try something along the lines of:

Code: Select all

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.

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: cell selection fails for some reason

Post by macropod »

Hi Robie,

I don't know why that would be happening. If you could post a cut-down document with the unmodified shapes, I could take a look at it.
Paul Edstein
[Fmr MS MVP - Word]

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: cell selection fails for some reason

Post by Robie »

macropod wrote:Hi Robie,

I don't know why that would be happening. If you could post a cut-down document with the unmodified shapes, I could take a look at it.
Thanks. Sorry, I have been away for a long weekend.

I will upload something tomorrow.

Robie

User avatar
DaveA
GoldLounger
Posts: 2599
Joined: 24 Jan 2010, 15:26
Location: Olympia, WA

Re: cell selection fails for some reason

Post by DaveA »

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 :evilgrin:
Genealogy....confusing the dead and annoying the living