|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我有一段vba代码,功能是把表格里面多个单元格内容输出到对应多个txt里面(这个是没问题的),但因为内容含有汉字和其他特殊符号,vba默认输出ansi格式txt的话,该txt内容无法被我其他后续软件处理识别,所以请高手帮忙写一段vba输出txt为utf-8的,百度包括在这里搜索到很多相关的教程,但我小白,简单的代码拼接和套用下没有效果(有的代码只能输出为一个txt,我的是需要大量输出的,见代码附件,也可以看下面的,谢谢!
代码.rar
(735 Bytes, 下载次数: 5)
=====================================================
Sub 导出()
Application.ScreenUpdating = False
n = Range("a65536").End(xlUp).Row '检测A列总行数
arr = Range("a2:i" & n) '存到数组,提升速度
For i = 1 To n - 1 '循环输出
outstr = ""
sname = arr(i, 1)
outstr = "我与" & arr(i, 1) & "的世界" '没有注释
If Len(arr(i, 2)) > 0 Then '如果内容不是为空的话,就组合内容
outstr = outstr & vbCrLf & vbCrLf & "提问" & arr(i, 2) & "解答" 'vbCrLf 是换行的意思
End If
If Len(arr(i, 3)) > 0 Then
outstr = outstr & vbCrLf & vbCrLf & "小明" & arr(i, 3) & "个棉花糖"
End If
If Len(arr(i, 4)) > 0 Then
outstr = outstr & vbCrLf & vbCrLf & "小四" & arr(i, 4) & "个棉花糖"
End If
If Len(arr(i, 5)) > 0 Then
outstr = outstr & vbCrLf & vbCrLf & "小六" & arr(i, 5) & "个棉花糖"
End If
If Len(arr(i, 6)) > 0 Then
outstr = outstr & vbCrLf & vbCrLf & "小五" & arr(i, 6) & "个棉花糖"
End If
If Len(arr(i, 7)) > 0 Then
outstr = outstr & vbCrLf & vbCrLf & "换成" & arr(i, 7) & "西瓜"
End If
If Len(arr(i, 7)) > 0 Then
outstr = outstr & vbCrLf & vbCrLf & "购买" & arr(i, 7) & "苹果"
End If
outstr = outstr & vbCrLf & "约定"
outstr = outstr & vbCrLf & "签名"
FullName = ThisWorkbook.Path & "\" & sname & ".txt"
Open FullName For Output As #1
Print #1, outstr;
Close #1
Next
Application.ScreenUpdating = True
MsgBox "导出完毕"
End Sub
=====================================================
|
|