Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 12-07-2012, 07:21 AM
delasson delasson is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Dec 2012
Posts: 2
delasson is on a distinguished road
Default Compare content of two ranges INCLUDING FORMATTING

I'm comparing the content of two ranges in Word like this:



If range1.Text = range2.Text Then
...
EndIf

This works fine for actual content, but I would like to include text formatting into the comparrison as well. So if I have two ranges with the same text, BUT the text in range1 is bold, I would like the comparrison to return false.

Any ideas?

Thanks
Reply With Quote
  #2  
Old 12-08-2012, 09:24 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,319
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

If you can rely on the correct use of Styles for the formatting, it simply becomes a matter of checking whether the same style names are used for the same ranges.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 12-10-2012, 01:48 AM
delasson delasson is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Dec 2012
Posts: 2
delasson is on a distinguished road
Default

Hi Paul
Thank you for your reply.
I’m sorry I wasn’t very specific in my question.
I would love to have an easy way to test for formatting changes without doing a specific test for every possible formatting element (font changes, highlighting, text effects, styles, …)
What I am looking for is a property (on the Range object) like the Text-property BUT it should also include formatting information. I was happy when I found out that the Range object actually has a property called FormattedText. When I read about it in the documentation, it sounds to me that this was what I was looking for, so instead of doing the test:
Rang1.Text = Range2.Text
I changed the test to:
Range1.FormattedText.Text = Range2.FormattedText.Text
But as I see it, the FormattedText.Text property contains the exact same information as the Text property on the Range object (no formatting information).
Can you – or someone else – explain me what I am able to do with the FormattedText-property on the Range object? Or are you aware of some other functionality that can help me?
Thanks ;-)
Reply With Quote
  #4  
Old 12-10-2012, 03:54 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,319
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Unless you can rely on Style-based comparisons (ie whatever formatting is used in the document relies entirely on the use of Styles), you will have to test every attribute individually. If you can rely on the use of Styles, it then becomes a matter of testing which Styles have been used, and where.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Tags
compare, formatting, range
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
WDFormatOriginalFormatting does not retain formatting when content pasted from RTF ramsgarla Word Tables 1 10-05-2012 02:35 AM
Send Email with VBA while also including formatting tylerg11 Outlook 0 07-27-2012 10:49 AM
Rich Text Content Control - Allow User Formatting keithacochrane Word 1 05-28-2012 05:06 PM
How to use named ranges in excel vba? bosve73 Excel Programming 4 01-25-2012 09:26 AM
Using COMPARE to compare more than two variables Wyskers Word 1 12-03-2011 01:37 AM


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


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft