我正在从PowerPoint项目(信息亭模式)中提取不同的可变用户输入,并将数据写入文本文件中。文本文件只能处理69个字符的限制(包括空格,标点符号,特殊字符...所有自由文本)。如果文本是简单的句子结构,我已经找到并修改了一些代码,可以满足我的大多数需求,但是,我剩下的问题是如何处理诸如Web地址或文件位置之类的文件(运行时间可能超过69个)长度)。另一个问题是,如果某个单词的一部分保留在69个字符的规则下,则将其分解。
示例:用户输入联系信息。
“ Kealoha Taylor Patrovillanovastronsky,(808)-555-5555,kt_p22 @ htecheng.org,https://www.htecheng.org/finance/htech/d8/cpt554/patrovillanovastonsky/”在此示例中,仅网站的字符为72个字符。
我想获取将以下内容写入文本文件的代码。
Kealoha Taylor Patrovillanovastronsky, (808)-555-5555, kt_p22@
htecheng.org, https://www.htecheng.org/finance/htech/d8/cpt554
/patrovillanovastonsky/
显然,每行可能会有所不同,具体取决于名称,电子邮件或网址的长度(如果有)
我的代码如下(将3个单独的字符串写入记事本):
'''
Sub Send2text()
Dim Str1, STRin, STRin1, STRin2, STRin3, STRin4, STRout As String
Dim ArrWords, ArrWords1, ArrWords2, ArrWords3, ArrWord4, STRWord As Variant
Dim FilePath As String
STRin = Slide4.UserInput.Text
STRin1 = Slide4.UserInput1.Text
STRin2 = Slide4.UserInput2.Text
STRin3 = Slide4.UserInput3.Text
STRin4 = Slide4.UserInput4.Text
ArrWords = Split(STRin, " ")
ArrWords1 = Split(STRin1, " ")
ArrWords2 = Split(STRin2, " ")
ArrWords3 = Split(STRin3, " ")
ArrWords4 = Split(STRin4, " ")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''' Open the text file and prepare it for updates ''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FilePath = "C:\Documents|History.txt"
TextFile = FreeFile
Open FilePath For Append As TextFile
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''' begin writing updates ''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For Each STRWord In ArrWords
If Len(STRout) + Len(STRWord) <= 69 Then
If STRout = "" Then STRout = STRWord Else STRout = STRout & " " & STRWord
ElseIf Len(STRout) + Len(STRWord) >= 69 Then
If Strl = "" Then
Str1 = STRout
Print #TextFile, Str1
STRout = " " & STRWord ' the indent is needed for the paragraph marker
Str1 = ""
GoTo Line1
End If
End If
Line1:
Next STRWord
Print #TextFile, STRout
STRout = ""
For Each STRWord In ArrWords1
If Len(STRout) + Len(STRWord) <= 69 Then
If STRout = "" Then STRout = STRWord Else STRout = STRout & " " & STRWord
ElseIf Len(STRout) + Len(STRWord) >= 69 Then
If Strl = "" Then
Str1 = STRout
Print #TextFile, Str1
STRout = " " & STRWord ' the indent is needed for the paragraph marker)
Str1 = ""
GoTo Line2
End If
End If
Line2:
Next STRWord
Print #TextFile, STRout
STRout = ""
For Each STRWord In ArrWords2
If Len(STRout) + Len(STRWord) <= 69 Then
If STRout = "" Then STRout = STRWord Else STRout = STRout & " " & STRWord
ElseIf Len(STRout) + Len(STRWord) >= 69 Then
If Strl = "" Then
Str1 = STRout
Print #TextFile, Str1
STRout = " " & STRWord ' the indent is needed for the paragraph marker)
Str1 = ""
GoTo Line3
End If
End If
Line3:
Next STRWord
Print #TextFile, STRout
STRout = ""
Close TextFile
End With
End Sub
'''
非常感谢您的协助。 问候, 罗伯特