S
Stuart Mattinson
I am trying to add the total of multipule tables together, I have the formula
below that I have added to the VBA of "This Document" so that when the
document opens the macro will run.
I have two questions :
1. Where to I place the Format(total, "#,###.00") so that I have the correct
deimal placing in the final total
2. Because I am running the macro every time the document opens I can end up
with the answer multipule times, I could ask the users to run it manually but
sometimes they forget and then the document will be mailed out without a
Grand Total. I have reied to add a Delete before the marco starts but it is
not working 100%
My Current Macro is :
Private Sub Document_Open()
ActiveDocument.Bookmarks("GrandTotal").Select
Selection.Delete
Dim i As Long, total As Double
Dim rsum As Range
total = Format(total, "#,###.00")
With ActiveDocument
For i = 1 To .Tables.Count
Set rsum = .Tables(i).Cell(6, 2).Range
rsum.End = rsum.End - 1
If IsNumeric(rsum.Text) Then
total = total + rsum.Text
End If
Next i
End With
ActiveDocument.Bookmarks("GrandTotal").Select
Selection = "R" & total
End Sub
below that I have added to the VBA of "This Document" so that when the
document opens the macro will run.
I have two questions :
1. Where to I place the Format(total, "#,###.00") so that I have the correct
deimal placing in the final total
2. Because I am running the macro every time the document opens I can end up
with the answer multipule times, I could ask the users to run it manually but
sometimes they forget and then the document will be mailed out without a
Grand Total. I have reied to add a Delete before the marco starts but it is
not working 100%
My Current Macro is :
Private Sub Document_Open()
ActiveDocument.Bookmarks("GrandTotal").Select
Selection.Delete
Dim i As Long, total As Double
Dim rsum As Range
total = Format(total, "#,###.00")
With ActiveDocument
For i = 1 To .Tables.Count
Set rsum = .Tables(i).Cell(6, 2).Range
rsum.End = rsum.End - 1
If IsNumeric(rsum.Text) Then
total = total + rsum.Text
End If
Next i
End With
ActiveDocument.Bookmarks("GrandTotal").Select
Selection = "R" & total
End Sub