![]() |
#1
|
|||
|
|||
![]()
Hi all
This is my first time attempting to use Word Macros and have copied some code from the internet. This is the code: Code:
Sub Summarise() ' ' Summarise Macro ' ' Application.ScreenUpdating = False Dim i As Integer, FldPos As Range With ActiveDocument For Each oPara In .Paragraphs With oPara.Range If .Information(wdWithInTable) = True Then With .Next If .Information(wdWithInTable) = False Then If .Text = vbCr Then .Delete End If End With End If End With Next For i = 1 To .Tables.Count With .Tables(i) .Rows.Add Set FldPos = .Cell(.Rows.Count, .Columns.Count).Range.Characters.Last With FldPos .Move wdCharacter, -1 .Fields.Add FldPos, Text:="=SUM(ABOVE) \# ""'Total: '£,0""", PreserveFormatting:=False .Fields.Unlink End With End With Next End With Application.ScreenUpdating = True End Sub Possible? The other problem I have is that i have 2 other tables on the page and the macro runs on those tables too. I was thinking of putting something in that said if the table has more than 2 rows, then run the macro above, else don't. Alas my VB skills are limited - if you know how i would do this too that would be very handy. Thanks in advance! Last edited by macropod; 01-29-2013 at 09:16 PM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
![]()
You could simply replace:
.Rows.Add with something like: Code:
While .Rows.Count < 20 .Rows.Add Wend PPS: You should declare all variables before using them - your oPara variable is undeclared and should be decalred as 'Dim oPara As Paragraph'
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
j2b3 | Word Tables | 3 | 07-19-2012 03:59 PM |
![]() |
gsrikanth | Excel | 5 | 01-19-2012 02:40 PM |
![]() |
gib65 | Excel | 2 | 12-09-2011 02:09 PM |
![]() |
Learner7 | Excel | 1 | 04-19-2011 02:45 AM |
![]() |
kyakobi | Excel | 5 | 12-07-2010 03:12 PM |