Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2021, 11:14 PM
soroush.kalantari soroush.kalantari is offline Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Windows 10 Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Office 2016
Competent Performer
Is there a way to stop macro modifications from undoing when Updating Word Linked Tables?
 
Join Date: Jun 2021
Posts: 124
soroush.kalantari is on a distinguished road
Default Is there a way to stop macro modifications from undoing when Updating Word Linked Tables?

I have written a macro to optimize the routine modifications (changing font, row height, size, etc.) I always make for the tables linked from Excel to Word. Now the problem is that when I update the tables (via right click/update Link), all the macro modifications are undone. Is there a remedy for this problem? (Note: the same doesn’t happen if the modifications are made manually (without macro). I use Word 2016. I have found this problem is not specific to my macro and is the case for every macro running on linked Word tables. See the following simple example which just autofits a table and determines its height). I have also posted this question on SuperUser and Quora. (Cross posting for not getting a satisfactory answer)

Sub autofit()



' autofit Macro

Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
Selection.Tables(1).Rows.Height = CentimetersToPoints(0.01)

End Sub
Reply With Quote
  #2  
Old 06-25-2021, 01:48 AM
macropod's Avatar
macropod macropod is offline Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Windows 10 Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,367
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Anything you do in Word to refresh a field - which includes the LINK fields that are used when Word sources data from Excel - will erase any formatting you have applied to the field's result. The behaviour is by design and cannot be overridden.

Contrary to what you say, it doesn't matter whether the change is made via a macro or manually. Since your macro doesn't do anything to refresh the link, I cannot see how that would affect any other formatting you have applied to the table. That said, I cannot see the point of setting the row heights to 0.1mm...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-25-2021, 07:00 AM
Charles Kenyon Charles Kenyon is offline Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Windows 10 Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,464
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Rather than a macro solution, or as part of a macro solution, look into styles and table styles. Use the tools that are built into Word.


You can use a CHARFORMAT switch on fields to help them maintain formatting.
Reply With Quote
  #4  
Old 06-27-2021, 06:15 PM
macropod's Avatar
macropod macropod is offline Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Windows 10 Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,367
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

A Charformat switch isn't going to do anything useful in a LINK field where a variety of formats are required. Nor will table Styles. About the only thing that will work is applying the required format to the source.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
macro, tables, updating



Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating INDEX leads to page margins modifications dum Word 3 03-01-2020 06:37 PM
Problem With Updating Linked Excel Tables in Word 2013 maverick1714 Word 6 09-30-2014 12:30 AM
Linked excel cells not updating in word lucky16 Word 0 09-10-2014 07:40 AM
Macro for replacing, copying and undoing. vthomeschoolmom Word VBA 1 12-05-2012 07:41 AM
Is there a way to stop macro modifications from undoing when Updating Word Linked Tables? Updating *from* a linked Word document hanvyj Word 2 03-01-2012 02:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft