Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-23-2014, 12:33 PM
Cosmo Cosmo is offline Moving formatted text from one table to another Windows Vista Moving formatted text from one table to another Office 2007
Competent Performer
Moving formatted text from one table to another
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Moving formatted text from one table to another

I have an issue moving formatted text from a cell in one table to another. If I just set the text property, everything works fine, but trying to get the text to keep the current formatting is proving much more work than necessary.



My initial testing just set the text property so:
Code:
 destTable.Cell(1,1).range.text = SourceTable.Cell(1,1).range.text
And that worked properly, but when I changed that one line to set the FormattedText, it would make a complete mess of the document, and usually crash:
Code:
 destTable.Cell(1,1).range.formattedText = SourceTable.Cell(1,1).range.formattedText
I found that stripping off the last few characters from the source range would do the trick, and the program would finish running without crashing, but not all of the text is correct. The last paragraph in each cell is now 11 point (the source is 9 point), and throughout, the font is inconsistent. The source table is all Calibri, but in any cell, some paragraphs are Calibri, and others will be Times.

All I want to do is set the contents of one cell to another, and maintain the same formatting. Why does this seem to be impossible!?
Reply With Quote
  #2  
Old 06-23-2014, 01:01 PM
Cosmo Cosmo is offline Moving formatted text from one table to another Windows Vista Moving formatted text from one table to another Office 2007
Competent Performer
Moving formatted text from one table to another
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

I am having better results using
Code:
SourceTable.Cell(1,1).range.copy
destTable.Cell(1,1).range.pasteandformat (wdFormatOriginalFormatting)
But I don't want to change the user's clipboard! I need a solution that doesn't rely on copy/paste.
Reply With Quote
  #3  
Old 06-23-2014, 07:41 PM
macropod's Avatar
macropod macropod is offline Moving formatted text from one table to another Windows 7 32bit Moving formatted text from one table to another Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

What you need to do is to transfer the paragraph format attached to the end-of-cell marker, along with the rest of the cell contents. For example:
Code:
Sub Demo()
Dim Tbl1 As Table, Tbl2 As Table
Dim Rng1 As Range, Rng2 As Range
Dim i As Long
With ActiveDocument
  Set Tbl1 = .Tables(1)
  Set Tbl2 = .Tables(2)
  For i = 1 To Tbl1.Range.Cells.Count
    Tbl2.Range.Cells(i).Range.Paragraphs.Last.Range.ParagraphFormat = _
      Tbl1.Range.Cells(i).Range.Paragraphs.Last.Range.ParagraphFormat
    Set Rng1 = Tbl1.Range.Cells(i).Range
      With Rng1
        .End = .End - 1
      End With
    Set Rng2 = Tbl2.Range.Cells(i).Range
      With Rng2
        .End = .End - 1
        .FormattedText = Rng1.FormattedText
      End With
  Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 06-24-2014, 05:59 AM
Cosmo Cosmo is offline Moving formatted text from one table to another Windows Vista Moving formatted text from one table to another Office 2007
Competent Performer
Moving formatted text from one table to another
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Thumbs up

Thanks again for your continued assistance, this is exactly what I needed!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoCorrect with Formatted Text pmokover Word 15 05-11-2017 08:50 PM
Moving formatted text from one table to another Inserted AutoText table incorrectly formatted - unless macro paused! Smallweed Word VBA 4 01-16-2014 03:15 PM
Moving formatted text from one table to another Text auto formatted as date format Aikeedoh Excel 5 09-06-2013 02:38 AM
Import formatted text from Word into PowerPoint parboy PowerPoint 0 07-06-2011 08:52 AM
Insert formatted table into word (mail merge) manojbmsce Mail Merge 0 09-25-2008 02:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:57 AM.


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