Excel Macros - Saving as tab delimited with the
我有几百本格式和结构完全相同的Excel工作簿。我需要准备每个文件以便稍后处理:
理想情况下,我可以打开所有需要运行它的工作簿,并对每个工作簿运行宏,将每个文件的原始名称保存为制表符分隔的文件,并在1-3中进行所有更改。
我在这段代码上一直出现语法错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Sub Macro4_eggplant() Dim newname as string newname = ThisWorkbook.FullName Rows("1:1").Select Selection.Delete Shift:=xlUp Columns("C:E").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("C2").Select ActiveCell.FormulaR1C1 ="Filename.xls" Range("C2").Select Selection.AutoFill Destination:=Range("Table4[Column1]") Range("Table4[Column1]").Select Range("D5").Select ActiveWorkbook.SaveAs Filename:= _ "/Users/matthewhughes/Desktop/""newname"".txt" _ , FileFormat:=xlText, CreateBackup:=False End Sub |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Sub Macro4_eggplant() Dim newname as String With ActiveSheet newname = Left(.Parent.Name, InstrRev(.Parent.Name,".") - 1) .Rows(1).Delete Shift:=xlUp .Columns("C:E").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove .Range("C2").FormulaR1C1 ="Filename.xls" ' or = .Parent.Name ? .Range("C2").AutoFill Destination:=.Range("Table4[Column1]") .Parent.SaveAs Filename:="/Users/matthewhughes/Desktop/" & newname &".txt", _ FileFormat:=xlText, _ CreateBackup:=False End With End Sub |
(我假设表4存在于某个地方。)