View Single Post
 
Old 08-18-2015, 01:46 PM
mikemike616 mikemike616 is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Aug 2015
Posts: 7
mikemike616 is on a distinguished road
Default

Okay so in the same document, I created a new macro with the code below. It successfully creates the bookmark but puts it in cell (2,1) instead of (2,2). Changing the code to put it in (2,1) puts it in the same spot. I don't understand what's happening here.

Furthermore, replacing ".InsertCrossReference" with ".Text = "test"" successfully sets the text of the specified cell to "test". It seems something is wrong with my bookmarks (they reference an XML linked content control if that makes a difference.) The thing that confuses me is that when I place the cursor in the cell and use "Selection.InsertCrossReference", it inserts the bookmark correctly, no problems.

Code:
Sub CrossRef()
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
    2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
    wdAutoFitFixed
With ActiveDocument.Range.Tables(4)
    With .Cell(2, 2).Range
        .InsertCrossReference ReferenceType:=wdRefTypeBookmark, ReferenceKind:=wdContentText, ReferenceItem:="DATE", InsertAsHyperlink:=True
    End With
End With
End Sub
Reply With Quote