1

I am trying to use vba in order to collect text from excel and put it in a word document.

using the following script, I get the the style to affect only the English letters but the letters in Hebrew does not follow.

Sub WriteToWord()

    Dim wordApp As Object
    Dim mydoc As Object

    Set wordApp = CreateObject("Word.Application")

    wordApp.Visible = True
    wordApp.Activate

    Set mydoc = wordApp.Documents.Add()

    With wordApp.Selection
        .Font.Size = 18
        .Font.Bold = True
        .TypeText ("a")
        .TypeText ("חדש")
    End With
End Sub
Olov
  • 1,103
  • 11
  • 27

1 Answers1

0

I tried to copy the Hebrew string you have there in the end, but for me, it doesn't encode correctly, as it just shows "???" in the editor and in the Word document (notice that I'm on a Swedish computer, so it might still show the correct characters for you=.

It seems that the VBA editor only supports the Windows-1252 encoding (https://stackoverflow.com/a/23678551/4663244), so I'm curious about how you work with these characters :)

Here is a related question about how to use Unicode characters in a VBA script: declaring a unicode string in vba in excel

Anyway, I got it to work if I used the function ChrW to write unicode characters (btw, I don't know for sure I used the correct characters, so please check that):

Sub WriteToWord()

    Dim wordApp As Object
    Dim mydoc As Object

    Set wordApp = CreateObject("Word.Application")

    wordApp.Visible = True
    wordApp.Activate

    Set mydoc = wordApp.Documents.Add()

    With wordApp.Selection
        .Font.Size = 18
        .Font.Bold = True
        .TypeText ("a")
        .TypeText (ChrW(1495) + ChrW(1491) + ChrW(1513))
    End With
End Sub
Olov
  • 1,103
  • 11
  • 27