数组是VBA中非常好用的功能
下面用代码来演示如何将txt的tab文件转入excel表格的方法
当中利用的转记工具就是数组
会写上一部分注释
Function saveFile()
Dim Temp, Temp2, Buf, Target As String, LRow_Output As Long, LCon_Output As Long, InputT, DelFile As String
Set Shet_Const = WbInput.Sheets("CONST") '设定变数的页面const
Name1 = "粘贴"
Set Shet_粘贴用 = WbInput.Sheets(Name1) '要粘贴txt文本的页面
With Shet_Const
File_name = .Range("G8").Value & ".txt"
DelFile = .Range("G9").Value & "\" & .Range("G8").Value & ".txt" '在变数页面取得所需文件的路径和名称
End With
Set Shet_Const = Nothing
Buf = ""
Target = SHT_CONST.Range("G9").Value & "\" & File_name
Application.EnableEvents = False
Set InputT = CreateObject("ADODB.Stream") '使用ADODB机能打开txt文件,因为可以指定txt的格式,可以规避乱码情况
With InputT