【问题标题】:VBA - How can you pull Cyrillic text into Powerpoint Label from .TXT FileVBA - 如何将西里尔文文本从 .TXT 文件中提取到 Powerpoint 标签中
【发布时间】:2023-03-26 23:34:01
【问题描述】:

我正在制作一个随机单词生成器,用于我的全球研究课上的西里尔字母游戏。我找到了 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

【问题讨论】:

  • 看看这是否回答了你的问题。 stackoverflow.com/questions/17698260/…。这可能是文本编码问题,例如ASCII 与 Unicode。
  • 谢谢。唯一的问题是,由于我不是程序员,我不知道如何将这些信息合并到我正在使用的内容中。我正在使用 YouTube 视频提供的代码,以便教师能够在课堂上使用,而无需知道如何编写代码。
  • 要使 VBA 与 unicode 一起正常工作,您需要对 Windows 系统进行更改。需要更改非 Unicode 程序的语言以匹配。
  • 我该怎么做?只需下载程序的语言包? (例如 PowerPoint 的编辑语言包?)
  • 更新:当我将 PowerPoint 编辑语言更改为俄语时,VBA 代码只是显示相同的乱码。我为 .txt 的编码选择了 UTF-8。

标签: vba powerpoint cyrillic


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    • 2016-09-27
    相关资源
    最近更新 更多