VBA - 如何从.TXT文件中将西里尔文本拉入Powerpoint标签

时间:2017-12-19 23:00:41

标签: vba powerpoint cyrillic

我正在制作一个随机单词生成器,用于我的全球研究课程,用于西里尔字母表的游戏。我发现PowerPoint 2016的VBA设置从文本文件中提取随机单词。问题是,它不会显示西里尔文。我尝试在VBA工具中更改编码。我已经确保为.txt文件尝试不同的编码设置,但我似乎无法在标签中获得实际的西里尔字母。

我正在使用的VBA代码是:

Public myArray, Word1
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
    If SSW.View.CurrentShowPosition = 2 Then
        Randomize
        Label1.Caption = ""

        Dim path
        path = ActivePresentation.path & "\words.txt"

        Open path For Input As #1
        filecontent = Input(LOF(1), #1)
        Close #1

        myArray = Split(filecontent, vbCrLf)
    End If
End Sub

Private Sub CommandButton1_Click()
    Word1 = Int((UBound(myArray)) * Rnd)
    Label1.Caption = myArray(Word1)
End Sub

Private Sub Label1_Click()
End Sub

1 个答案:

答案 0 :(得分:0)

Try reading a line at a time from the file rather than using LOF:

Function FileToString(sFileName as string) as String

    Dim FileNum As Integer
    Dim sBuf As String
    Dim sTemp as String

    FileToString = False    ' by default

    If ExistFile(sFileName ) Then
        FileNum = FreeFile
        sTemp = ""
        Open sFileName For Input As FileNum

        While Not EOF(FileNum)
            Line Input #FileNum, sBuf
            sTemp= sTemp & sBuf & vbCrLf
        Wend

        Close FileNum
        FileToString = sTemp

End Function