请高手指点、简化、解决“有中文全角字节导致错乱情况”?
Sub abc()
Dim n, i, j, k, cd2 As Integer
Dim str As String
Dim str0 As String
Dim str1 As String * 21
Dim str2 As String * 12
Dim str3 As String * 32
Dim str4 As String * 60
Dim str5 As String * 16
Dim str6 As String * 12
Dim str7 As String * 60
Set fp = CreateObject("Scripting.FileSystemObject")
Set f = fp.CreateTextFile("c:\1.txt", True)
Application.ScreenUpdating = False '关闭屏幕刷新
p = Range("i65536").End(xlUp).Row '读取当前列行末号
Application.ScreenUpdating = True '打开屏幕刷新
i = 2
j = 1
Do While Cells(i, 1) <> ""
str = ""
For j = 1 To 7 '读取1-7列
'cd2 = LenB(StrConv(Trim(Cells(i, j)), vbFromUnicode)) '读取当前单元格字节长度,计算字符串的字节数
'MsgBox i & ":" & j & "=" & cd2
If (Trim(Cells(i, j).Value)) <> "" Then
str0 = Trim(Cells(i, j).Value)
Else
str0 = " "
End If
If j = 1 Then
str1 = str0
str0 = str1
End If
If j = 2 Then
str2 = str0
str0 = str2
End If
If j = 3 Then
str3 = str0
str0 = str3
End If
If j = 4 Then
str4 = str0
str0 = str4
End If
If j = 5 Then
str5 = str0
str0 = str5
End If
If j = 6 Then
str6 = str0
str0 = str6
End If
If j = 7 Then
str7 = str0
str0 = str7
End If
str = str + str0
str = str + "|"
Next j
str = str + Trim(Cells(i, 15).Value)
f.writeline (str)
i = i + 1
Loop
f.Close
Shell "notepad.exe " & "c:\1.txt", vbNormalFocus
End Sub
[此贴子已经被作者于2008-6-15 11:43:28编辑过]