在Vba Split()函数显示错误,我不知道什么问题? [英] In Vba Split() Function Shows The Error, I Dont Know What Problem?
本文介绍了在Vba Split()函数显示错误,我不知道什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Sub paras()
Dim iLower < span class =code-keyword> As Integer ,iUpper As 整数,iCount 作为 整数,temp As 字符串
Dim p As word.Paragraph
Dim txt As 变体
Dim w 作为 整数
Dim str As 字符串
Dim i As 整数
Dim j As 整数
Dim rng As 字符串
Dim iparCount As 整数
Dim strArray As 范围
Dim sArray
Dim sMyPara As String
w = ActiveDocument.Range.words.count
iparCount = ActiveDocument.Paragraphs.count
对于 i = 1 iparCount
sMyPara = ActiveDocument.Paragraphs(i).Range.text
设置 strArray = ActiveDocument.Paragraphs(i).Range
sArray = 拆分(strArray, ,)
iUpper = UBound(sArray)
iLower = 1
Dim bSorted 作为 布尔值
bSorted = 错误
执行 不 bSorted
bSorted = True
对于 iCount = iLower 要 iUpper - 1
str2 = StrComp(sArray(iCount),sArray(iCount + 1 ),vbTex tCompare)
如果 str2 = 1 那么
temp = sArray(iCount + 1 )
sArray(iCount + 1 )= sArray(iCount)
sArray(iCount)= temp
bSorted = False
结束 如果
下一步 iCount
iUpper = iUpper - 1
循环
rng = sArray(iCount)
下一步 i
结束 Sub
解决方案
因为,显然,strArray
是范围
(它应该是字符串
)。
Sub paras()
Dim iLower As Integer, iUpper As Integer, iCount As Integer, temp As String
Dim p As word.Paragraph
Dim txt As Variant
Dim w As Integer
Dim str As String
Dim i As Integer
Dim j As Integer
Dim rng As String
Dim iparCount As Integer
Dim strArray As Range
Dim sArray
Dim sMyPara As String
w = ActiveDocument.Range.words.count
iparCount = ActiveDocument.Paragraphs.count
For i = 1 To iparCount
sMyPara = ActiveDocument.Paragraphs(i).Range.text
Set strArray = ActiveDocument.Paragraphs(i).Range
sArray = Split(strArray, ",")
iUpper = UBound(sArray)
iLower = 1
Dim bSorted As Boolean
bSorted = False
Do While Not bSorted
bSorted = True
For iCount = iLower To iUpper - 1
str2 = StrComp(sArray(iCount), sArray(iCount + 1), vbTextCompare)
If str2 = 1 Then
temp = sArray(iCount + 1)
sArray(iCount + 1) = sArray(iCount)
sArray(iCount) = temp
bSorted = False
End If
Next iCount
iUpper = iUpper - 1
Loop
rng = sArray(iCount)
Next i
End Sub
解决方案
Because, apparently,strArray
is aRange
(it should be aString
).
这篇关于在Vba Split()函数显示错误,我不知道什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文