我有这段从文本文件中读取的代码,当行以“Q”开头时,它是一个问题,“R”和“W”分别是读取到形状的错误和正确答案。
但问题是,如果文本中的任何位置有逗号,我的 powerpoint 宏会将其视为新行。请帮忙解决这个问题吗?
这是代码
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
Use Line Input
代替Input
.
Input
进行一些解析,包括用逗号分隔以及转换一些值,例如#TRUE#和#NULL#。Line Input
输入完整的行并且不进行任何转换。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)