Share via

Macro problem__

Anonymous
2010-09-10T20:17:13+00:00

Hello, how can I easily insert special characters from other language (ș, ț, î, ă, â) within the VBA script instead of ChrW(537) or ChrW(539)?

<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>RO</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]-->

The below string should be: știu că pot rezolva asta, dar cine îți va spune cum? știe cineva țara?

VBA script:

Sub Macro1()

'

' Macro1 Macro

'

'

    Selection.TypeText Text:=ChrW(537) & "tiu că pot rezolva asta, dar cine î" _

         & ChrW(539) & "i va spune cum? " & ChrW(537) & "tie ci"

    Selection.TypeText Text:="neva " & ChrW(539) & "ara?"

    Selection.TypeParagraph

    Selection.TypeParagraph

End Sub

thanks

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2010-09-11T11:11:30+00:00

    Thanks for posting that - it will come in quite useful :)

    I have already added the following to my useful macros add-in.

    Sub AnsiCode()

    Dim myData As DataObject

    Dim vChar As Variant

    Dim sCode As String

    Set myData = New DataObject

    For Each vChar In Selection.Characters

       sCode = sCode & "ChrW(" & AscW(vChar) & ") & "

    Next

    sCode = Left(sCode, Len(sCode) - 3)

    MsgBox sCode & vbCr & vbCr & "Copied to clipboard!"

    myData.SetText sCode

    myData.PutInClipboard

    End Sub

    <Tony Jollans [MVP]> wrote in message news:*** Email address is removed for privacy ***...

    As others have said you cannot really do this. The VBA editor is an ANSI

    (non-Unicode) text editor and the only options you have are characters in

    the basic ASCII set plus those in whatever code page you are using. Any code

    point higher than 255 and you need to use the CHrW method.

    If you have a lot of this to code up it would probably be worth writing a

    little routine to pull text from a document body and generate the code -

    just something simple for your own use like this would, at least, avoid

    mistakes ..

    For Each char In Selection.Characters

      code = code & "ChrW(" & AscW(char) & ") & "

    Next

    .. and you could then copy the code from the immediate window and into its

    proper place, but you could make it more sophisticated if you wanted to.


    Enjoy,

    Tony

    www.WordArticles.com

    "cispas2000" wrote in message

    news:*** Email address is removed for privacy ***...

    Hello, how can I easily insert special characters from other language (Èâ"¢,

    Èâ?º, î, ÄÆ', â) within the VBA script instead of ChrW(537) or ChrW(539)?

    <!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View>

    <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/>

    <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/>

    <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>

    <w:IgnoreMixedContent>false</w:IgnoreMixedContent>

    <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>

    <w:DoNotPromoteQF/> <w:LidThemeOther>RO</w:LidThemeOther>

    <w:LidThemeAsian>X-NONE</w:LidThemeAsian>

    <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>

    <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/>

    <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/>

    <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/>

    <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/>

    <w:Word11KerningPairs/> <w:CachedColBalance/> <w:UseFELayout/>

    </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin

    m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/>

    <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc

    m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim

    m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument>

    </xml><![endif]-->

    The below string should be: Èâ"¢tiu cÄÆ' pot rezolva asta, dar cine îÈâ?ºi va

    spune cum? Èâ"¢tie cineva Èâ?ºara?

    VBA script:

    Sub Macro1()

    '

    ' Macro1 Macro

    '

    '

       Selection.TypeText Text:=ChrW(537) & "tiu cÄÆ' pot rezolva asta, dar

    cine î" _

            & ChrW(539) & "i va spune cum? " & ChrW(537) & "tie ci"

       Selection.TypeText Text:="neva " & ChrW(539) & "ara?"

       Selection.TypeParagraph

       Selection.TypeParagraph

    End Sub

    thanks


    Enjoy,

    Tony

    www.WordArticles.com


    Graham Mayor - Word MVP

    www.gmayor.com

    Posted via the Communities Bridge

    http://communitybridge.codeplex.com/

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-09-11T08:43:49+00:00

    As others have said you cannot really do this. The VBA editor is an ANSI

    (non-Unicode) text editor and the only options you have are characters in

    the basic ASCII set plus those in whatever code page you are using. Any code

    point higher than 255 and you need to use the CHrW method.

    If you have a lot of this to code up it would probably be worth writing a

    little routine to pull text from a document body and generate the code -

    just something simple for your own use like this would, at least, avoid

    mistakes ..

    For Each char In Selection.Characters

    code = code & "ChrW(" & AscW(char) & ") & "

    Next

    .. and you could then copy the code from the immediate window and into its

    proper place, but you could make it more sophisticated if you wanted to.

    --

    Enjoy,

    Tony

    www.WordArticles.com

    "cispas2000" wrote in message

    news:*** Email address is removed for privacy ***...

    > Hello, how can I easily insert special characters from other language (È™,

    > È›, î, ă, â) within the VBA script instead of ChrW(537) or ChrW(539)?

    >

    > <!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View>

    > <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/>

    > <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/>

    > <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>

    > <w:IgnoreMixedContent>false</w:IgnoreMixedContent>

    > <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>

    > <w:DoNotPromoteQF/> <w:LidThemeOther>RO</w:LidThemeOther>

    > <w:LidThemeAsian>X-NONE</w:LidThemeAsian>

    > <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>

    > <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/>

    > <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/>

    > <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/>

    > <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/>

    > <w:Word11KerningPairs/> <w:CachedColBalance/> <w:UseFELayout/>

    > </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin

    > m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/>

    > <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc

    > m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim

    > m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument>

    > </xml><![endif]-->

    > The below string should be: È™tiu că pot rezolva asta, dar cine îÈ›i va

    > spune cum? știe cineva țara?

    >

    > VBA script:

    >

    > Sub Macro1()

    > '

    > ' Macro1 Macro

    > '

    > '

    >    Selection.TypeText Text:=ChrW(537) & "tiu că pot rezolva asta, dar

    > cine î" _

    >         & ChrW(539) & "i va spune cum? " & ChrW(537) & "tie ci"

    >    Selection.TypeText Text:="neva " & ChrW(539) & "ara?"

    >    Selection.TypeParagraph

    >    Selection.TypeParagraph

    > End Sub

    >

    > thanks

    >

    >


    Enjoy,

    Tony

    www.WordArticles.com

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2010-09-11T07:49:04+00:00

    Am 10.09.2010 22:17, schrieb cispas2000:

    how can I easily insert special characters from other language (ș, ț, î, ă, â) within the VBA script instead of ChrW(537) or ChrW(539)?

    You can map your chars using a special char added with a number in VBA and replace it with your special char.

    Andreas.

    Sub Macro2()

      Selection.TypeText Text:=ReplaceMap("@537tiu ca( pot " & _

        "rezolva asta, dar cine î@539i va spune cum? @537tie ci")

      Selection.TypeText Text:=ReplaceMap("neva @539ara?")

      Selection.TypeParagraph

      Selection.TypeParagraph

    End Sub

    Function ReplaceMap(ByVal S As String) As String

      Dim Item

      For Each Item In Array("537", "539")

        S = Replace(S, "@" & Item, ChrW(Item))

      Next

      ReplaceMap = S

    End Function

    Was this answer helpful?

    0 comments No comments
  4. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2010-09-10T22:41:03+00:00

    Do you mean without having to use ChrW(537) or ChrW(539)?

    If that is correct, I do not think that you can do it any other way.

    -- Hope this helps.

    Doug Robbins - Word MVP,

    dkr[atsymbol]mvps[dot]org

    Posted via the Community Bridge

    "cispas2000" wrote in message news:*** Email address is removed for privacy ***...

    Hello, how can I easily insert special characters from other language (ș, ț, î, ă, â) within the VBA script instead of ChrW(537) or ChrW(539)?<!--  [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>RO</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]-->

    The below string should be: știu că pot rezolva asta, dar cine îți va spune cum? știe cineva țara?

    VBA script:Sub Macro1()

    '

    ' Macro1 Macro

    '

    '

        Selection.TypeText Text:=ChrW(537) & "tiu că pot rezolva asta, dar cine î" _

             & ChrW(539) & "i va spune cum? " & ChrW(537) & "tie ci"

        Selection.TypeText Text:="neva " & ChrW(539) & "ara?"

        Selection.TypeParagraph

        Selection.TypeParagraph

    End Sub

    *thanks

    *


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org

    Was this answer helpful?

    0 comments No comments