Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

detecting unwanted formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Devlon - 25 Jan 2005 08:34 GMT
Dear All,

Working on a project I encountered  some problems ...

I need to develop some vba code to check documents if the are well formated.

The text in the document may only be formatted with character- and
paragrapgh styles i've designed.
I've also created a charachter style "bad formated". I need to apply this
style to all pieces of text that are nof formated with the styles of my
chooice, even the pieces of text that have the right paragraph style but
also have been set to "bold" or "underlined" or something else ...

I also need to find and change all bad quotes (") and change them to "smart"
quotes ...

Has anyone have some idees ... Does know were i can find this on the web ?

Thank you very much in advance ....

High regards,

JD
Jezebel - 25 Jan 2005 11:14 GMT
If you're using Word 2003, check the 'Mark formatting inconsistencies'
checkbox: any formatting that deviates from a defined style is marked with a
squiggly blue underline.

AutoFormat deals with straight vs. smart quotes.

> Dear All,
>
[quoted text clipped - 19 lines]
>
> JD
John Devlon - 25 Jan 2005 15:24 GMT
Hi,

Thanx for your reply...

I've tested the build in features you mentioned but it does not work well.

Also, the VBA code I'm trying to develop and I'm looking for, will be used
in Word prior to 2003.

JD

> If you're using Word 2003, check the 'Mark formatting inconsistencies'
> checkbox: any formatting that deviates from a defined style is marked with
[quoted text clipped - 29 lines]
>>
>> JD
Jezebel - 25 Jan 2005 21:56 GMT
> Hi,
>
> Thanx for your reply...
>
> I've tested the build in features you mentioned but it does not work well.

Doesn't work well how? It seems to me it works all too well :)

> Also, the VBA code I'm trying to develop and I'm looking for, will be used
> in Word prior to 2003.

In that case, you've got a sh.t-load of work to do. Probably simplest is
along these lines:

1. Iterate the paragraphs of the document.

2. Compare the paragraph's formatting features with those of the underlying
style. There are three possibilities --

a) They match
b) They are set to something else.
c) They are 'undefined', meaning that the paragraph contains mixed values.
For text properties (like the style name), undefined is given as an empty
string. For numeric values (like type size) undefined is given as 999999
(check how many nines, but I think it's six).

3. If the paragraph contains mixed formatting, iterate its characters and
text them individually.
John Devlon - 26 Jan 2005 23:50 GMT
Dear Jezebel,

Many thanx for your feedback...

I already developed some basic code ... And this works fine... Afcourse this
has to be extended...
One thing i noticed is that when paragraph styles are mixed with character
formating, the code does not detect any mistakes... Do you have any
suggestions how i can detect these occurenses ... I can not find any
'undefined' ...

Thanx

John

Sub Controle_Styles()
   Dim Sty1 As String
   Dim bolFound As Boolean
   bolFound = False

   Dim acceptedStyle(10) As String
   acceptedStyle(1) = "[text]"
   acceptedStyle(2) = "[ht]"
   acceptedStyle(3) = "[t1]"

   For Each para In ActiveDocument.Paragraphs
       Sty1 = para.Style

       For i = 0 To UBound(acceptedStyle)
           If acceptedStyle(i) = Sty1 Then
               bolFound = True
           End If
       Next

       If bolFound = False Then
         para.Style = ActiveDocument.Styles("[FOUT]")
       End If

       bolFound = False

   Next para

End Sub

>> Hi,
>>
[quoted text clipped - 27 lines]
> 3. If the paragraph contains mixed formatting, iterate its characters and
> text them individually.
Jezebel - 27 Jan 2005 00:19 GMT
You'll need to be more thorough in your checking. At present you're checking
only the name of the style. You need to check the properties also --

Dim pStyle as Word.Style

Set pStyle = ActiveDocument.Styles("[text]")

With para.Range.Font
   If .Bold = 9999999 then
       ... contains mixed values
   elseif .Bold <> pStyle.Font.Bold then
       ... differs from definition

   ... etc. Repeat for font name, size, italic, etc etc, etc

With para.Range.ParagraphFormat
With para.Range.Borders
With para.Range.ListFormat
etc

As I said, you have a heap of work to do if you want to be thorough.

> Dear Jezebel,
>
[quoted text clipped - 71 lines]
> > 3. If the paragraph contains mixed formatting, iterate its characters and
> > text them individually.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.