PDA

View Full Version : Preserve formatting after update - WORD Table



JoWalmsley
05-15-2023, 10:23 PM
Hi

I am new on here so I hope I have posted this in the right place.

I have some VBA code that takes a table + title in specific cell + source information in another cell in Excel and pastes it into Word using the 'Link and keep source formatting' option.

This works fine getting the table and other informatin into word, however when the links are updated the formatting goes all over the place.

I ran some tests and I believe that if the 'Preserve formatting after update' box is checked in Word for each table then this retains the formatting. The only way I have found to do this in the code is when it is first pasted into word, but this doesn't retain the formatting from the Excel file.

Basically I think what I am looking for is a piece of code that can be tagged on the end of what I have already that checks the 'Preserve formatting after update' box after everything else has happened.

Can anyone help with this please?

Thank you
Jo

Aussiebear
05-16-2023, 01:19 AM
Welcome to VBAX Jo. Please be patient and someone will be along shortly to assist you. BTW, you posted in the Site and Forum related sub forum, but I have moved this to the correct forum.

Aussiebear
05-16-2023, 08:18 PM
Bump

Aussiebear
05-16-2023, 08:40 PM
Hmmm.. I would have thought one of the Word guru's would have been by, by now. Okay I went searching and found this piece of code which might give you a hint


Sub TestMemoGen()
Dim objWord As Object
Dim ws2 As Worksheet

Application.ScreenUpdating = False
Set ws2 = ThisWorkbook.Sheets("Word Export")
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\Users\ Tester\Word Test Sim.docm"

With objWord.ActiveDocument
.Bookmarks("DENT_90").Range.Text = ws2.Range("DENT_90").DisplayFormat.NumberFormat
End With
Set objWord = Nothing
Application.EnableEvents = True
End Sub


Not having any experience in word VBA, I don't know if this works.