0

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 autofit a table and determine its height). I have also posted this question on Quora

Sub autofit()

' autofit Macro
    
    Selection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
    Selection.Tables(1).Rows.Height = CentimetersToPoints(0.01)
      
End Sub
3
  • Can you post your macro in your question? Which version of Word? superuser.com/help/how-to-ask -- have you considered using instead Quick Tables or Table Styles for your formatting? Jun 1, 2021 at 17:13
  • (1) I encourage you to indent your code properly. (2) Try to produce a minimal example — the shortest possible macro that demonstrates the problem. I see that you have eight Selection.Borders(…).LineStyle = wdLineStyleNone statements; I suspect you would have the same problem if you deleted seven of them — or even all eight. (3) What do you mean by “when I update the tables”? Jun 1, 2021 at 20:37
  • I have edited my question to address your comments. Jun 2, 2021 at 3:05

0

You must log in to answer this question.

Browse other questions tagged .