3

行が「Q」で始まる場合、テキストファイルから読み取るこのコードがあり、「R」と「W」はそれぞれ間違った答えと正しい答えであり、形状に読み取られます。ただし、問題は、テキストのどこかにコンマがあると、パワーポイント マクロがそれを新しい行として認識することです。これを修正する方法について何か助けてください。ここにコードがあります

Open ActivePresentation.Path & "\" & "questions.txt" For Input As #1
nextSlideNum = 1
nextAnswerNum = 1
Do Until EOF(1)
    Input #1, nextLine
    If Left$(nextLine, 1) = "Q" Then 'The line starts with Q; it's a question
        nextSlideNum = nextSlideNum + 1
        Set oSld = _
            ActivePresentation.Slides.AddSlide(nextSlideNum, _
            ActivePresentation.SlideMaster.CustomLayouts(2))
        oSld.Shapes(1).TextFrame.TextRange.Text = _
            Trim(Right$(nextLine, Len(nextLine) - 1))
        nextAnswerNum = 1
    ElseIf Left$(nextLine, 1) = "R" Then 'Right answer
        Set oShp = ActivePresentation.Slides(nextSlideNum).Shapes _
            .AddShape(msoShapeActionButtonCustom, 100, _
            120 + (85 * (nextAnswerNum - 1)), 500, 75)
        oShp.TextFrame.TextRange.Text = Trim(Right$(nextLine, Len(nextLine) - 1))
        oShp.ActionSettings(ppMouseClick).Action = ppActionRunMacro
        oShp.ActionSettings(ppMouseClick).Run = "RightAnswerButton"
        nextAnswerNum = nextAnswerNum + 1
    ElseIf Left$(nextLine, 1) = "W" Then 'Wrong answer
        Set oShp = ActivePresentation.Slides(nextSlideNum).Shapes _
            .AddShape(msoShapeActionButtonCustom, 100, _
            120 + (85 * (nextAnswerNum - 1)), 500, 75)
        oShp.TextFrame.TextRange.Text = Trim(Right$(nextLine, Len(nextLine) - 1))
        oShp.ActionSettings(ppMouseClick).Action = ppActionRunMacro
        oShp.ActionSettings(ppMouseClick).Run = "WrongAnswerButton"
        nextAnswerNum = nextAnswerNum + 1
    ElseIf Trim(nextLine) = "" Then
        'Ignore blank lines
    Else
        MsgBox _
            "Sorry, I don't know what to do with: " _
            & Chr$(13) & nextLine
    End If
Loop
4

1 に答える 1