Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 29th, 2006, 03:44 AM
Authorized User
 
Join Date: Sep 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Preserve Formatting on Update

Hi all;

Hope someone can help with this one...

I've created code to import 8 tables from a specified spreadsheet as linked objects. The code then goes on to format the tables and title and footnote text. This means that the Excel document has different formatting to the Word doc so on update the formatting is taken from Excel and wipes my formatting in Word.

There is an option in Word (Edit > Links) "Preserve formatting on update", which works a treat but I can't work out how to do it with VBA code.

It is possible to do it with Shapes and Inline shapes:

Sub PreserveFmtg()
    ThisDocument.Shapes(1).OLEFormat _
        .PreserveFormattingOnUpdate = True
End Sub


But does anyone know of a method to do it with tables?
Thanks

 
Old September 29th, 2006, 08:33 AM
Authorized User
 
Join Date: Sep 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just to let you know - I fixed this myself!
If you're interested:

OLD CODE:

Code:
'import Table + source
     oXL.Sheets("Key financials").Select
            oXL.Range("A8:H20").Select
            oXL.Selection.Copy
     With oWordDoc.ActiveWindow
         Selection.PasteExcelTable True, False, False
     End With


NEW CODE:

Code:
'import Table + source
     oXL.Sheets("Key financials").Select
            oXL.Range("A8:H20").Select
            oXL.Selection.Copy
     With oWordDoc.ActiveWindow
         Selection.PasteExcelTable True, True, False
     End With


The only change here is the second variable on the PasteExcelTable which has changed from False to True - this forces preserving Word formatting chnages rather than updating from the Excel sheet.

Just for interest the first variable sets whether the object is linked, the second whether to preserve formatting, and the third if False pastes as HTML - True pastes as RTF.

Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
preserve spaces in boundfield Ivision ASP.NET 2.0 Basics 0 April 29th, 2008 03:16 AM
Access will not preserve the table order. Admiral_Hook Access 4 April 23rd, 2008 02:43 PM
preserve form values in classic asp tausif.mohammed Classic ASP Basics 5 December 1st, 2007 04:54 PM
Preserve Hyperlinks when Sending HTML Worksheet Ahrenl Excel VBA 4 February 8th, 2005 02:52 PM
preserve caps with regexp.replace dhaywirex Classic ASP Basics 4 March 2nd, 2004 12:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.