Home > Mobile >  VBA ActiveDocument.Tables(2).Cell(1, 2).Range Problem
VBA ActiveDocument.Tables(2).Cell(1, 2).Range Problem

Time:06-22

I have a problem with the following code.

objTable.Cell(1, 1).Range.Text = "Link:"
Dim rngTable As Range
Set rngTable = ActiveDocument.Tables(2).Cell(1, 2).Range
rngTable.MoveEndWhile Chr(7) & Chr(13), wdBackward
objTable.Cell(1, 2).Range.FormattedText = rngTable

With

Set rngTable = ActiveDocument.Tables(2).Cell(1, 2).Range
rngTable.MoveEndWhile Chr(7) & Chr(13), wdBackward

I read an AddIn link "{ Link 2134 }" into rngTable

and with

objTable.Cell(1, 2).Range.FormattedText = rngTable

I write it in a different place in my Word.

My problem is the link is not fully copied and written. The back bracket is always missing from the actual link "{ Link... }". So the result is always "{ Link... ".

So word does not recognize the link.

I've already tried it with wdForward, it works, but it shuffles all the Word lines in such a way that they aren't usable. Does anyone have an idea?

CodePudding user response:

Change:

rngTable.MoveEndWhile Chr(7) & Chr(13), wdBackward
objTable.Cell(1, 2).Range.FormattedText = rngTable

to:

rngTable.End = rngTable.End - 1
objTable.Cell(1, 2).Range.FormattedText = rngTable.FormattedText
  • Related