The macro is very simple. I want to find the font size other then
default and insert a tag before and after the text to list the font
size.

I am running into two issues
First, getting the default font size for the document.
Second, I think I broke my current script and I can't figure out
where it went wrong LOL.

Any help would be appreciated.

-TIA-

[code]

Private Sub ConvertSize()

Dim fSize&

If convertFontSize = False Then Exit Sub

If DefaultFontSize = 12 Then DefaultFontSize = 12
fSize = 12

For fSize = 1 To 50
If fSize > DefaultFontSize + 1 Or fSize < DefaultFontSize - 1 Then
'at least two points difference
ActiveDocument.Select
With Selection.Find

.ClearFormatting
.Font.Size = fSize
.Text = ""
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Forward = True
.Wrap = wdFindContinue

Do While .Execute
With Selection

If Len(.Text) > 1 And InStr(1, .Text, vbCr) Then
' Just process the chunk before any newline
characters
' We'll pick-up the rest with the next search
.Collapse
.MoveEndUntil vbCr
End If

' Don't bother to markup newline characters
(prevents a loop, as well)
If Not .Text = vbCr Then
If fSize = DefaultFontSize Then
.InsertBefore "[size=" & fSize & "]"
.InsertAfter "[/size]"
End If
End If

If useDefaultStyle Then .Style =
ActiveDocument.Styles(DefaultStyleName) 'must be localized to your
language, see CONST on top
.Font.Size = DefaultFontSize
'.Collapse wdCollapseEnd
'.MoveLeft , 4, True
'ClearFormatting

End With
Loop
End With
End If
Next

End Sub

[/code]

Re: Help with a Macro for Word by Helmut

Helmut
Tue Jun 06 10:20:08 CDT 2006

Hi,

I don't know of a default font size for a document.
You may mean the font size of the paragraph template "normal",
like this:

MsgBox ActiveDocument.Styles("Normal").Font.Size

The rest of the job depends so much
on the document's structure and size,
that is is almost impossible to give an advice.

If every second string longer then one
is of a different size than the next or
the preceding string and the document is very large,
then the approach could be quite different
from dealing with a simple and short document
with large strings of the same font size.

As to your code:

> If DefaultFontSize = 12 Then DefaultFontSize = 12
Doesn't make sense.
> fSize = 12
ok. fsize = 12
and now fsize takes on the values from 1 to 50
> For fSize = 1 To 50
which doesn't make sense either.

> If Not .Text = vbCr Then
> If fSize = DefaultFontSize Then
> .InsertBefore "[size=" & fSize & "]"
> .InsertAfter "[/size]"
> End If
> End If

Would mean, you tag only text with the default fontsize,
then you wouldn't need a loop a all.

hm..., I wonder.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Re: Help with a Macro for Word by MKruer

MKruer
Tue Jun 06 12:13:04 CDT 2006

Helmut Weber wrote:
> Hi,
>
> I don't know of a default font size for a document.
> You may mean the font size of the paragraph template "normal",
> like this:
>
> MsgBox ActiveDocument.Styles("Normal").Font.Size
>
> The rest of the job depends so much
> on the document's structure and size,
> that is is almost impossible to give an advice.
>
> If every second string longer then one
> is of a different size than the next or
> the preceding string and the document is very large,
> then the approach could be quite different
> from dealing with a simple and short document
> with large strings of the same font size.
>

I think that it is a reasonable assumption that the default size would
be the size specified in the nomal.dot. The only other way that I would
think that you could find the "default" size would be to search the
document and find the size that occurs the most. This however would
take up too much processing.

> As to your code:
>
> > If DefaultFontSize = 12 Then DefaultFontSize = 12
> Doesn't make sense.
> > fSize = 12
> ok. fsize = 12
> and now fsize takes on the values from 1 to 50
> > For fSize = 1 To 50
> which doesn't make sense either.
>
> > If Not .Text = vbCr Then
> > If fSize = DefaultFontSize Then
> > .InsertBefore "[size=" & fSize & "]"
> > .InsertAfter "[/size]"
> > End If
> > End If
>
> Would mean, you tag only text with the default fontsize,
> then you wouldn't need a loop a all.
>

The original, original code came from a Macro Word2MediaWikiPlus. In it
the original values were 10 and 12, and only included a change between
Large and Small, or 9pt and 18pt fonts. I was looking to refine this
system to be more robust by allowing for any size fonts.

> hm..., I wonder.
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"


Re: Help with a Macro for Word by Jean-Guy

Jean-Guy
Tue Jun 06 13:36:15 CDT 2006

MKruer@gmail.com was telling us:
MKruer@gmail.com nous racontait que :

> Helmut Weber wrote:
>> Hi,
>>
>> I don't know of a default font size for a document.
>> You may mean the font size of the paragraph template "normal",
>> like this:
>>
>> MsgBox ActiveDocument.Styles("Normal").Font.Size
>>
>> The rest of the job depends so much
>> on the document's structure and size,
>> that is is almost impossible to give an advice.
>>
>> If every second string longer then one
>> is of a different size than the next or
>> the preceding string and the document is very large,
>> then the approach could be quite different
>> from dealing with a simple and short document
>> with large strings of the same font size.
>>
>
> I think that it is a reasonable assumption that the default size would
> be the size specified in the nomal.dot. The only other way that I
> would think that you could find the "default" size would be to search
> the document and find the size that occurs the most. This however
> would take up too much processing.

Helmut meant the font size defined in the style named "Normal", not the
default size of the template called "Normal,dot".
As Helmut, wrote, there is not such thing as a default font size for a
document, but the default style is the "Normal" style (A newly created blank
document from the Normal.dot template contains a single paragraph with the
Normal style applied).

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Help with a Macro for Word by MKruer

MKruer
Tue Jun 06 15:48:51 CDT 2006

Thanks,

Thats even better.


Jean-Guy Marcil wrote:
> MKruer@gmail.com was telling us:
> MKruer@gmail.com nous racontait que :
>
> > Helmut Weber wrote:
> >> Hi,
> >>
> >> I don't know of a default font size for a document.
> >> You may mean the font size of the paragraph template "normal",
> >> like this:
> >>
> >> MsgBox ActiveDocument.Styles("Normal").Font.Size
> >>
> >> The rest of the job depends so much
> >> on the document's structure and size,
> >> that is is almost impossible to give an advice.
> >>
> >> If every second string longer then one
> >> is of a different size than the next or
> >> the preceding string and the document is very large,
> >> then the approach could be quite different
> >> from dealing with a simple and short document
> >> with large strings of the same font size.
> >>
> >
> > I think that it is a reasonable assumption that the default size would
> > be the size specified in the nomal.dot. The only other way that I
> > would think that you could find the "default" size would be to search
> > the document and find the size that occurs the most. This however
> > would take up too much processing.
>
> Helmut meant the font size defined in the style named "Normal", not the
> default size of the template called "Normal,dot".
> As Helmut, wrote, there is not such thing as a default font size for a
> document, but the default style is the "Normal" style (A newly created blank
> document from the Normal.dot template contains a single paragraph with the
> Normal style applied).
>
> --
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org


Re: Help with a Macro for Word by MKruer

MKruer
Fri Jun 09 13:24:46 CDT 2006

I must be loosing it. Can someone take a look and tell me why this is
not working correctly.

-TIA-

Private Sub ConvertSize()

Dim CurrentFontSize&
Dim DocFontSize&


DocFontSize = ActiveDocument.Styles("Normal").Font.Size

For CurrentFontSize = 1 To 72

ActiveDocument.Select
With Selection.Find

.ClearFormatting
.Font.Size = DocFontSize
.Text = ""
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Forward = True
.Wrap = wdFindContinue

Do While .Execute
With Selection

If Len(.Text) > 1 And InStr(1, .Text, vbCr) Then
' Just process the chunk before any newline
characters
' We'll pick-up the rest with the next search
.Collapse
.MoveEndUntil vbCr
End If
'DiffFontSize = CurrentFontSize - DefaultFontSize

' Don't bother to markup newline characters
(prevents a loop, as well)
If .Text = vbCr Then
If CurrentFontSize = DocFontSize Then
.InsertBefore "[size=" & CurrentFontSize -
DocFontSize & "]"
.InsertAfter "[/size]"
End If
End If

If useDefaultStyle Then .Style =
ActiveDocument.Styles(DefaultStyleName) 'must be localized to your
language, see CONST on top
.Font.Size = DocFontSize

End With
Loop
End With
'End If
Next

End Sub


Re: Help with a Macro for Word by Helmut

Helmut
Sun Jun 11 05:53:12 CDT 2006

Hi MKruer,

>Can someone take a look and tell me why this is
>not working correctly.

forgive me for an excursus into theory,
but in informatics there is nothing like
"correct" or "failure" or even "error" or so,
in a very strict sense, IMHO.

What is called "correct" is defined by your expectations.
What do you expect?

If the default font size is 14 and you want to tag
all text of size 14, except paragraph marks, then:

Sub Macro6()
' tag all text of font size 14
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Font.Size = 14
While .Execute
rDcm.InsertBefore "[14]"
If Right(rDcm, 1) = Chr(13) Then
rDcm.End = rDcm.End - 1
rDcm.InsertAfter "[14]"
rDcm.Start = rDcm.End + 2
Else
rDcm.InsertAfter "[14]"
End If
rDcm.Start = rDcm.End
rDcm.End = ActiveDocument.Range.End
Wend
End With
End Sub

If you want to tag all text except of font size 14,
in the range from 1 to 50, then:

Sub Macro6x()
' tag all text of font size <> 14
Dim rDcm As Range
Dim l As Long
Set rDcm = ActiveDocument.Range
' set all paragraph marks to standard value
' and exclude them by this from processing
With rDcm.Find
.Text = Chr(13)
While .Execute
rDcm.Font.Size = 14
Wend
End With

Set rDcm = ActiveDocument.Range
For l = 1 To 50
If l <> 14 Then
With rDcm.Find
.Font.Size = l
While .Execute
rDcm.Select ' for testing only
rDcm.Font.Size = 14
rDcm.InsertBefore "[" & l & "]"
rDcm.InsertAfter "[" & l & "]"
rDcm.Start = rDcm.End
rDcm.End = ActiveDocument.Range.End
Wend
End With
End If
Next
End Sub

Well, I wonder...

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"










Re: Help with a Macro for Word by MKruer

MKruer
Sun Jun 11 22:35:29 CDT 2006

I think I need to go back and relearn VB. Thanks for the code snippet.
I noticed that it only runs through the page once which is a good
thing, but it doesn't maker anything higher then the specified front
for some reason. Also what I was trying to accomplish with the normal
text was to find what font the user was using and base all the scaling
upon that. The document has 10pt as the normal then we should assume
that what they consider 8pt font is really 10pt font when normalized
against the web standard 12pt font.

Sub Macro7()

' tag all text of font size <> dfSize
Dim rDcm As Range
Dim l As Long
Dim m As Long

m = ActiveDocument.Styles("Normal").Font.Size
'get the curent normal size of the document

Set rDcm = ActiveDocument.Range
' set all paragraph marks to standard value
' and exclude them by this from processing
With rDcm.Find
.Text = Chr(13)
While .Execute
rDcm.Font.Size = 12
Wend
End With

Set rDcm = ActiveDocument.Range
For l = 1 To 72
If l <> 72 Then
With rDcm.Find
.Font.Size = l
While .Execute
rDcm.Select ' for testing only
rDcm.Font.Size = 12
rDcm.InsertBefore "[size=" & l & "]"
rDcm.InsertAfter "[/size]"
rDcm.Start = rDcm.End
rDcm.End = ActiveDocument.Range.End
Wend
End With
End If
Next
End Sub


Helmut Weber wrote:
> Hi MKruer,
>
> >Can someone take a look and tell me why this is
> >not working correctly.
>
> forgive me for an excursus into theory,
> but in informatics there is nothing like
> "correct" or "failure" or even "error" or so,
> in a very strict sense, IMHO.
>
> What is called "correct" is defined by your expectations.
> What do you expect?
>
> If the default font size is 14 and you want to tag
> all text of size 14, except paragraph marks, then:
>
> Sub Macro6()
> ' tag all text of font size 14
> Dim rDcm As Range
> Set rDcm = ActiveDocument.Range
> With rDcm.Find
> .Font.Size = 14
> While .Execute
> rDcm.InsertBefore "[14]"
> If Right(rDcm, 1) = Chr(13) Then
> rDcm.End = rDcm.End - 1
> rDcm.InsertAfter "[14]"
> rDcm.Start = rDcm.End + 2
> Else
> rDcm.InsertAfter "[14]"
> End If
> rDcm.Start = rDcm.End
> rDcm.End = ActiveDocument.Range.End
> Wend
> End With
> End Sub
>
> If you want to tag all text except of font size 14,
> in the range from 1 to 50, then:
>
> Sub Macro6x()
> ' tag all text of font size <> 14
> Dim rDcm As Range
> Dim l As Long
> Set rDcm = ActiveDocument.Range
> ' set all paragraph marks to standard value
> ' and exclude them by this from processing
> With rDcm.Find
> .Text = Chr(13)
> While .Execute
> rDcm.Font.Size = 14
> Wend
> End With
>
> Set rDcm = ActiveDocument.Range
> For l = 1 To 50
> If l <> 14 Then
> With rDcm.Find
> .Font.Size = l
> While .Execute
> rDcm.Select ' for testing only
> rDcm.Font.Size = 14
> rDcm.InsertBefore "[" & l & "]"
> rDcm.InsertAfter "[" & l & "]"
> rDcm.Start = rDcm.End
> rDcm.End = ActiveDocument.Range.End
> Wend
> End With
> End If
> Next
> End Sub
>
> Well, I wonder...
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"


Re: Help with a Macro for Word by HelmutWeber

HelmutWeber
Mon Jun 12 06:27:01 CDT 2006

Hi,

Sub Macro7x()

' tag all text of font size <> dfSize
Dim rDcm As Range
Dim l As Long
Dim m As Long


' m = ActiveDocument.Styles("Standard").Font.Size ' german
m = ActiveDocument.Styles("Normal").Font.Size ' english
'get the curent normal size of the document


Set rDcm = ActiveDocument.Range
' set all paragraph marks to standard value
' and exclude them by this from processing
With rDcm.Find
.Text = Chr(13)
While .Execute
rDcm.Font.Size = m ' <<<
Wend
End With

For l = 1 To 72
Set rDcm = ActiveDocument.Range ' <<<<
If l <> m Then ' <<<<
With rDcm.Find
.Font.Size = l
While .Execute
rDcm.Select ' for testing only
rDcm.Font.Size = m ' <<<<<<<<<<<<<
rDcm.InsertBefore "[size=" & l & "]"
rDcm.InsertAfter "[/size]"
rDcm.start = rDcm.End
rDcm.End = ActiveDocument.Range.End
Wend
End With
End If
Next
End Sub

--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000 (german versions)



Re: Help with a Macro for Word by MKruer

MKruer
Mon Jun 12 13:40:14 CDT 2006

Now it is working much, much better. Thank you. I corrected the ability
to adjust the font size based upon 12pt so now if the document is set
to 10pt, it treats all fonts as if 10pt was actually 12pt and adds the
fonts size accordingly.

The is one more question though, and I am not sure if its just my
document or a bug in the code. When it comes to 12pt fonts, it always
skips encoding it with the correct tag. I walk through the debug and it
looks like it should work, but it doesn't. Any ideas

Also if you don't mind I would like to include your name in the
credits, its only fair.

Final output (Base 10pt font)

[size=9]7[/size]
[size=10]8[/size]
[size=11]9[/size]
10
[size=13]11[/size]
12
[size=15]13[/size]
[size=16]14[/size]



'Special thanks to Helmut Weber for help with coding and efficiency.

Sub ConvertSize()

' tag all text of font size <> dfSize
Dim rDcm As Range
Dim l As Long
Dim m As Long
Dim n As Long

' m = ActiveDocument.Styles("Standard").Font.Size ' german
m = ActiveDocument.Styles("Normal").Font.Size ' english
'get the curent normal size of the document
n = m - 12
'calculate the differencebetween the normal size of the document and
the web size (12)

Set rDcm = ActiveDocument.Range
' set all paragraph marks to standard value
' and exclude them by this from processing
With rDcm.Find
.Text = Chr(13)
While .Execute
rDcm.Font.Size = m ' <<<
Wend
End With

For l = 1 To 72
Set rDcm = ActiveDocument.Range ' <<<<
If l <> m Then ' <<<<
With rDcm.Find
.Font.Size = l
While .Execute
rDcm.Select ' for testing only
rDcm.Font.Size = m ' <<<<<<<<<<<<<
rDcm.InsertBefore "[size=" & l - n & "]"
rDcm.InsertAfter "[/size]"
rDcm.Start = rDcm.End
rDcm.End = ActiveDocument.Range.End
Wend
End With
End If
Next


Helmut Weber wrote:
> Hi,
>
> Sub Macro7x()
>
> ' tag all text of font size <> dfSize
> Dim rDcm As Range
> Dim l As Long
> Dim m As Long
>
>
> ' m = ActiveDocument.Styles("Standard").Font.Size ' german
> m = ActiveDocument.Styles("Normal").Font.Size ' english
> 'get the curent normal size of the document
>
>
> Set rDcm = ActiveDocument.Range
> ' set all paragraph marks to standard value
> ' and exclude them by this from processing
> With rDcm.Find
> .Text = Chr(13)
> While .Execute
> rDcm.Font.Size = m ' <<<
> Wend
> End With
>
> For l = 1 To 72
> Set rDcm = ActiveDocument.Range ' <<<<
> If l <> m Then ' <<<<
> With rDcm.Find
> .Font.Size = l
> While .Execute
> rDcm.Select ' for testing only
> rDcm.Font.Size = m ' <<<<<<<<<<<<<
> rDcm.InsertBefore "[size=" & l & "]"
> rDcm.InsertAfter "[/size]"
> rDcm.start = rDcm.End
> rDcm.End = ActiveDocument.Range.End
> Wend
> End With
> End If
> Next
> End Sub
>
> --
> Greetings from Bavaria, Germany
> Helmut Weber, MVP WordVBA
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000 (german versions)


Re: Help with a Macro for Word by HelmutWeber

HelmutWeber
Tue Jun 13 04:47:01 CDT 2006

Hi,

this is my input:
4 5 6 7 8 9 10 11 12 13 14 15 16¶
whereby each number is formatted in the size of the number.

This is my output with your unchanged code.

[size=6]4[/size] [size=7]5[/size] [size=8]6[/size] [si-ze=9]7[/size]
[size=10]8[/size] [size=11]9[/size] 10 [si-ze=13]11[/size] [size=14]12[/size]
[size=15]13[/size] [si-ze=16]14[/size] [size=17]15[/size] [size=18]16[/size]¶

--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000


Re: Help with a Macro for Word by MKruer

MKruer
Tue Jun 13 09:26:59 CDT 2006

Ok I think I found the issue. I could change the default font size, but
not necessarily apply it to the document. So as it was going through it
would see a 10pt font, skip it, then come to the 12pt font and see that
it was also "normal" and skip it as well. It was only till after I
hit apply to the entire document that it fixed this issue.

I guess that pretty much closes out this thread.

Thanks for the help.

I will be starting a new one to convert lists into BBCode. I got a base
line, but its not that great.

Thanks Again.

Helmut Weber wrote:
> Hi,
>
> this is my input:
> 4 5 6 7 8 9 10 11 12 13 14 15 16=B6
> whereby each number is formatted in the size of the number.
>
> This is my output with your unchanged code.
>
> [size=3D6]4[/size] [size=3D7]5[/size] [size=3D8]6[/size] [si-ze=3D9]7[/si=
ze]
> [size=3D10]8[/size] [size=3D11]9[/size] 10 [si-ze=3D13]11[/size] [size=3D=
14]12[/size]
> [size=3D15]13[/size] [si-ze=3D16]14[/size] [size=3D17]15[/size] [size=3D1=
8]16[/size]=B6
>
> --
> Greetings from Bavaria, Germany
> Helmut Weber, MVP WordVBA
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000