F
Fernando Peralta
OS: Mac OS 10.3.5
Word X for Mac
I have a big Word table for which each row in column 2 is going to be
marked with a bookmark. The idea is to automate the creation of the
bookmarks. The name of the bookmark is being read from column 1.
Following is the code to automate the process of creating the
bookmarks. The problem resides with using the string read in column 1
as the bookmark name. When running the sub I always get "Bad Bookmark
Name". When using the commented out expression (marked (1) at the
left) I realized that there are extra spaces which have to do with
the length of the string being defined when declaring the string
variable. I have tried to use (* SIZE) when declaring the string to
make its length known (though not the desired solution... just used as
test to understand a bit more), yet the "bad bookmark name" problem
persists.
Sub CreateBookmarks()
Dim rows As Integer
Dim bookmarkName As String
rows = ThisDocument.Tables(1).rows.Count
For Count = 2 To rows
bookmarkName = ThisDocument.Tables(1).Cell(Count,
1).Range.Text
'(1) bookmarkName = Chr$(34) & bookmarkName & Chr$(34)
ThisDocument.Bookmarks.Add Name:=bookmarkName, _
Range:=ThisDocument.Tables(1).Cell(Count, 2).Range
MsgBox bookmarkName
Next Count
End Sub
Thanks in advance,
Fernando
Word X for Mac
I have a big Word table for which each row in column 2 is going to be
marked with a bookmark. The idea is to automate the creation of the
bookmarks. The name of the bookmark is being read from column 1.
Following is the code to automate the process of creating the
bookmarks. The problem resides with using the string read in column 1
as the bookmark name. When running the sub I always get "Bad Bookmark
Name". When using the commented out expression (marked (1) at the
left) I realized that there are extra spaces which have to do with
the length of the string being defined when declaring the string
variable. I have tried to use (* SIZE) when declaring the string to
make its length known (though not the desired solution... just used as
test to understand a bit more), yet the "bad bookmark name" problem
persists.
Sub CreateBookmarks()
Dim rows As Integer
Dim bookmarkName As String
rows = ThisDocument.Tables(1).rows.Count
For Count = 2 To rows
bookmarkName = ThisDocument.Tables(1).Cell(Count,
1).Range.Text
'(1) bookmarkName = Chr$(34) & bookmarkName & Chr$(34)
ThisDocument.Bookmarks.Add Name:=bookmarkName, _
Range:=ThisDocument.Tables(1).Cell(Count, 2).Range
MsgBox bookmarkName
Next Count
End Sub
Thanks in advance,
Fernando