|
如题:已将nx12.TXT导入EXCEL整理并成功另存为nx12-1.TXT
可以再次打开EXCEL时提示找不到宏了??
Sub 清空表()
Cells.Select
Selection.Delete Shift:=xlUp
End Sub
Sub 导入()
清空表
H = Left(ThisWorkbook.Name, InStr(ThisWorkbook.Name, ".") - 1) '获取当前工作簿不带后缀名的工作簿名称
If Dir(ActiveWorkbook.Path & "\" & H & ".txt") <> "" Then '判断txt文件是否存在
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & ActiveWorkbook.Path & "\" & H & ".txt", Destination:= _
Range("$A$1"))
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(2, 2, 2, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Else
MsgBox "指定的文件夹不存在,或与Excel不同名请检查!"
End If
整理
End Sub
Sub 整理()
Columns("B:B").Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
End Sub
Sub 导出()
ChDir "C:\Documents and Settings\Administrator\桌面\VBA"
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\Administrator\桌面\VBA\nx11-1.txt", FileFormat:= _
xlUnicodeText, CreateBackup:=False
End Sub
|
|