I apologize for the very basic nature of my first post, but I am attempting to learn VBA on my own. Looking through these forums has helped immensely, but I've come to a problem I can't find an answer to online.
I have a table, and have written macros to add rows to the table and bookmark the rows as they are added. So, the first macro I run adds 3 rows, another adds 2, etc. and the rows are bookmarked appropriately. However, I have noticed that after the first bookmark is added, any rows added to the table below that are included in said first bookmark, as well as any bookmarks applied to them. I do not want this, as I have other macros written to delete lines based on bookmarks and I don't want to delete from the bookmark all the way down. If you can think of a way to cut off the bookmark and not extend it when new rows are added I would very much appreciate your insight. Here is the code to my first macro.
P.S. This is my first macro ever, so I would also be grateful for any tips on cleaner code or more efficient methods.
Thanks,
Goose
I have a table, and have written macros to add rows to the table and bookmark the rows as they are added. So, the first macro I run adds 3 rows, another adds 2, etc. and the rows are bookmarked appropriately. However, I have noticed that after the first bookmark is added, any rows added to the table below that are included in said first bookmark, as well as any bookmarks applied to them. I do not want this, as I have other macros written to delete lines based on bookmarks and I don't want to delete from the bookmark all the way down. If you can think of a way to cut off the bookmark and not extend it when new rows are added I would very much appreciate your insight. Here is the code to my first macro.
Code:
Sub CabExtend()
'
' CabExtend Macro
'
'
'SECTION 0
ActiveDocument.Tables(4).Rows.Add
ActiveDocument.Tables(4).Rows.Add
ActiveDocument.Tables(4).Rows.Add
Dim CabRows As Integer
CabRows = ActiveDocument.Tables(4).Rows.Count
Dim CabCells As Range
With ActiveDocument
Set CabCells = .Range(Start:=.Tables(4).Cell(CabRows - 2, 1).Range.Start, End:=.Tables(4).Cell(CabRows - 2, 5).Range.End)
CabCells.Bold = True
CabCells.Cells.Merge
CabCells.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
Dim CabCells2 As Range
With ActiveDocument
Set CabCells2 = .Range(Start:=.Tables(4).Cell(CabRows - 1, 1).Range.Start, End:=.Tables(4).Cell(CabRows, 5).Range.End)
CabCells2.Bold = False
CabCells2.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
Dim CabCells3 As Range
With ActiveDocument
Set CabCells3 = .Range(Start:=.Tables(4).Cell(CabRows - 1, 1).Range.Start, End:=.Tables(4).Cell(CabRows - 1, 4).Range.End)
CabCells3.Cells.Merge
End With
ActiveDocument.Tables(4).Rows(CabRows - 2).Cells(1).Range.Text = "Cab Extend/Retract"
ActiveDocument.Tables(4).Rows(CabRows - 1).Cells(1).Range.Text = "Set cab extend/retract speed: Start with flow control closed, then open 2-1/2 turns."
ActiveDocument.Tables(4).Rows(CabRows).Cells(1).Range.Text = "Check cab extend/retract timing."
ActiveDocument.Tables(4).Rows(CabRows).Cells(2).Range.Text = "17-20 sec"
ActiveDocument.Tables(4).Rows(CabRows).Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
Dim ALLCabCells As Range
With ActiveDocument
Set ALLCabCells = .Range(Start:=.Tables(4).Cell(CabRows - 2, 1).Range.Start, End:=.Tables(4).Cell(CabRows, 1).Range.End)
ActiveDocument.Bookmarks.Add Name:="CAB", Range:=ALLCabCells
End With
End Sub
Thanks,
Goose