Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Thu, 4 Sep 2008 01:42:27 -0700 (PDT),    group: microsoft.public.word.vba.general        back       


How to correct a mistake into macro?   
Hello.
There is one macro (below) which converting numbers to text (it was
published on site by Allan Wayatt "WordTips" -
http://wordtips.vitalnews.com/Pages/T000203_Converting_Numbers_to_Text.html).
But the Cardtext field number format has the limitation: max number is
999.999
If I use these macro with the number more then 999.999 (e.g.
123456789) then I get error "Type mismatch" for line "sBigStuff =
Trim(Int(Str(Val(sDigits) / 1000000)))".
Is it possible to repair these macro? How?
The macro (by Allen Wayatt):

Sub BigCardText()
    Dim sDigits As String
    Dim sBigStuff As String

    sBigStuff = ""

    ' Select the full number in which the insertion point is located
    Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdMove
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

    ' Store the digits in a variable
    sDigits = Trim(Selection.Text)

    If Val(sDigits) > 999999 Then
        If Val(sDigits) <= 999999999 Then
            sBigStuff = Trim(Int(Str(Val(sDigits) / 1000000)))
            ' Create a field containing the big digits and
            ' the cardtext format flag
            Selection.Fields.Add Range:=Selection.Range, _
              Type:=wdFieldEmpty, Text:="= " + sBigStuff + " \*
CardText", _
              PreserveFormatting:=True

            ' Select the field and copy it
            Selection.MoveLeft Unit:=wdWord, Count:=1,
Extend:=wdExtend
            sBigStuff = Selection.Text & " million "
            sDigits = Right(sDigits, 6)
        End If
    End If
    If Val(sDigits) <= 999999 Then
        ' Create a field containing the digits and the cardtext format
flag
        Selection.Fields.Add Range:=Selection.Range, _
          Type:=wdFieldEmpty, Text:="= " + sDigits + " \* CardText", _
          PreserveFormatting:=True

        ' Select the field and copy it
        Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
        sDigits = sBigStuff & Selection.Text

        ' Now put the words in the document
        Selection.TypeText Text:=sDigits
        Selection.TypeText Text:=" "
    Else
        MsgBox "Number too large", vbOKOnly
    End If
End Sub

Thank you very much.
date: Thu, 4 Sep 2008 01:42:27 -0700 (PDT)   author:   avkokin

Re: How to correct a mistake into macro?   
Change that line to this

sBigStuff = CStr(Val(sDigits) \ 1000000)

Note that \ is used instead of /. The \ operator is for integer division.


-- 
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

"avkokin"  wrote in message 
news:09582bf5-6e8a-486c-86f9-74cc1e467e35@q26g2000prq.googlegroups.com...
> Hello.
> There is one macro (below) which converting numbers to text (it was
> published on site by Allan Wayatt "WordTips" -
> http://wordtips.vitalnews.com/Pages/T000203_Converting_Numbers_to_Text.html).
> But the Cardtext field number format has the limitation: max number is
> 999.999
> If I use these macro with the number more then 999.999 (e.g.
> 123456789) then I get error "Type mismatch" for line "sBigStuff =
> Trim(Int(Str(Val(sDigits) / 1000000)))".
> Is it possible to repair these macro? How?
> The macro (by Allen Wayatt):
>
> Sub BigCardText()
>    Dim sDigits As String
>    Dim sBigStuff As String
>
>    sBigStuff = ""
>
>    ' Select the full number in which the insertion point is located
>    Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdMove
>    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
>
>    ' Store the digits in a variable
>    sDigits = Trim(Selection.Text)
>
>    If Val(sDigits) > 999999 Then
>        If Val(sDigits) <= 999999999 Then
>            sBigStuff = Trim(Int(Str(Val(sDigits) / 1000000)))
>            ' Create a field containing the big digits and
>            ' the cardtext format flag
>            Selection.Fields.Add Range:=Selection.Range, _
>              Type:=wdFieldEmpty, Text:="= " + sBigStuff + " \*
> CardText", _
>              PreserveFormatting:=True
>
>            ' Select the field and copy it
>            Selection.MoveLeft Unit:=wdWord, Count:=1,
> Extend:=wdExtend
>            sBigStuff = Selection.Text & " million "
>            sDigits = Right(sDigits, 6)
>        End If
>    End If
>    If Val(sDigits) <= 999999 Then
>        ' Create a field containing the digits and the cardtext format
> flag
>        Selection.Fields.Add Range:=Selection.Range, _
>          Type:=wdFieldEmpty, Text:="= " + sDigits + " \* CardText", _
>          PreserveFormatting:=True
>
>        ' Select the field and copy it
>        Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
>        sDigits = sBigStuff & Selection.Text
>
>        ' Now put the words in the document
>        Selection.TypeText Text:=sDigits
>        Selection.TypeText Text:=" "
>    Else
>        MsgBox "Number too large", vbOKOnly
>    End If
> End Sub
>
> Thank you very much.
date: Thu, 4 Sep 2008 10:03:42 +0100   author:   Jonathan West

Re: How to correct a mistake into macro?   
Jonathan, thank you very much.
date: Thu, 4 Sep 2008 13:46:56 +0400   author:   akokin

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us