Home > Software engineering >  Word tables VBA batch adding bookmarks
Word tables VBA batch adding bookmarks

Time:09-17

Never done before word project, in the word is not very familiar with VBA, although learned VB, has returned to the teacher,
Problems first, give a word form in the batch in order to add bookmarks, to do with the following code at the beginning, not found the problem, such as data inserted into a program in c #, is a big problem, because the bookmarks are selected according to the whole grid, so using c # to do input insert, then insert to the entire grid data, such as directly lead to abnormal form,
 Sub TestAddMarket () 

Dim num As Integer
Num=0

Dim MyBk As a Bookmark
For Each MyBk In ActiveDocument. Bookmarks
MyBk. Delete
Next


For r=3 To 15 Step 1

For c=3 To 23 Step 1
Selection. Tables (1). The Cell (r, c). Range. Bookmarks. Add (" TextBox "& amp; C + + num 1 * 21)
Next c
Num=num + 1
Next r

End Sub


Then the along while, found to be the Range is a collection of need when using VBA to do insert for the cursor, then to insert again,
Here is to meet the requirements of the code, didn't do too much leaner, post, for your reference,
 Sub TestAddMarket () 

Dim num As Integer
Num=0

Dim MyBk As a Bookmark
For Each MyBk In ActiveDocument. Bookmarks
MyBk. Delete
Next


For r=7 To 8 Step 1

For c=1 To 3 Step 1
Selection. Tables (1). The Cell (r, c). Range. Bookmarks. Add (" TextBox "& amp; C + + num 1 * 21)
Selection. GoTo I:=wdGoToBookmark, Name:=(" TextBox "& amp; C + + num 1 * 21)
ActiveDocument. Bookmarks ((" TextBox "& amp; C + + num 1 * 21)). The Delete
Selection. EndKey
Selection. The Bookmarks. Add (" TextBox "& amp; C + + num 1 * 21), Selection. Range
Next c
Num=num + 1
Next r

End Sub
  •  Tags:  
  • VBA
  • Related