![]() |
|
#1
|
|||
|
|||
|
I have a word doc with multiple tables.
Each table needs to sum automatically in the last row of the table. I was using the Sum(above) formula and chatgpt help to get a macro that auto updates fields whenever you move the outside of a cell in the table but it was not working. It needs to update automatically with every change in the table. Not when you save, or open, or print. I know this is possible as I am trying to replicate a word doc that has already been circulating. Due to protection on the document I cannot get into the macro or edit the file to my needs. Can anyone help me out? Here are some things i have tried: 1. ' Updates all table formulas automatically when the document opens Private Sub Document_Open() Call UpdateAllTableFormulas End Sub ' Updates all table formulas when content controls are exited or entered Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl) Call UpdateAllTableFormulas End Sub Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Call UpdateAllTableFormulas End Sub ' Loops through all tables and updates only formula fields Sub UpdateAllTableFormulas() Dim t As Table Dim f As Field For Each t In ThisDocument.Tables For Each f In t.Range.Fields If f.Type = wdFieldFormula Then f.Update End If Next f Next t End Sub 2. ' Automatically updates all table formulas like =SUM(ABOVE) Private Sub Document_WindowSelectionChange(ByVal Sel As Selection) On Error Resume Next ' Only run if cursor is inside a table If Sel.Information(wdWithInTable) Then Dim f As Field ' Loop through all fields in the table For Each f In Sel.Tables(1).Range.Fields ' Update only formula fields If f.Type = wdFieldFormula Then f.Update Next f End If End Sub 3. Private Sub Document_WindowSelectionChange(ByVal Sel As Selection) On Error Resume Next If Sel.Information(wdWithInTable) Then ' Update only formula fields in the table Dim f As Field For Each f In Sel.Tables(1).Range.Fields If f.Type = wdFieldFormula Then f.Update Next f End If End Sub 4. ' Place this in ThisDocument Private Sub Document_WindowSelectionChange(ByVal Sel As Selection) On Error Resume Next ' Only run if cursor is inside a table If Sel.Information(wdWithInTable) Then ' Update all fields in the current table Sel.Tables(1).Range.Fields.Update End If End Sub Last edited by wordygirly; 10-22-2025 at 11:53 AM. Reason: Adding Previous Attempts |
| Tags |
| auto update, formula, update fields |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
auto sort data formula without macro
|
monisankar | Excel | 2 | 01-15-2017 06:54 PM |
| Error 5941 when running my macro to auto populate fields throughout the word doc | VBAnovice1 | Word VBA | 2 | 05-26-2015 01:35 AM |
| Creating a Custom List that Updates when one of the data fields is filtered | anthrus | Excel | 1 | 11-13-2014 11:58 PM |
| Auto Update Fields Macro | kveldulv | Outlook | 0 | 06-07-2013 02:30 PM |
| Word 2007 TOC Updates to Include Tables and Styles | rphox2003 | Word | 6 | 10-21-2012 06:41 AM |