下面是长宏的最后几行,我必须为自己的业务生成销售文件。宏可以正常工作,并且可以完全按照我的期望导出,但是我想做一个小的更改。
我导出的文件在A列中包含10位数字的列表,下面的代码使最终读为XXEND,然后加上几行空行。
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Application.Goto Cells(Rows.Count, "A").End(xlUp).Offset(1), Scroll:=True
ActiveCell.FormulaR1C1 = "XXEND"
Range("A1").Select
Application.Goto Cells(Rows.Count, "A").End(xlUp).Offset(2), Scroll:=True
ActiveCell.FormulaR1C1 = "'"
Range("A1").Select
ActiveWorkbook.SaveAs FileName:="/Users/LucasWayne/Desktop/Websales.txt", FileFormat:=xlText, CreateBackup:=False
Shell ("/Users/LucasWayne/Desktop/WebSalesToK4.app")
ActiveWorkbook.Close
End Sub
有时,我的列表在A列中没有值,而XXEND是整个工作簿中的唯一值。 如果是这样,那么在输入XXEND之前,如果A列中没有值,我想提早终止宏,而是直接关闭excel文件而不保存。
有人有什么建议吗?
谢谢!
答案 0 :(得分:0)
您无法关闭宏,然后关闭工作簿,因此下面的代码仅退出宏:
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Application.Goto Cells(Rows.Count, "A").End(xlUp).Offset(1), Scroll:=True
If Not WorksheetFunction.Subtotal(103, Range("A:A")) > 1 Then Exit Sub 'This counts the number of cell in column A with something in it and assumes there's a header - if there isn't a header ten just change the 1 to 0
ActiveCell.FormulaR1C1 = "XXEND"
Range("A1").Select
Application.Goto Cells(Rows.Count, "A").End(xlUp).Offset(2), Scroll:=True
ActiveCell.FormulaR1C1 = "'"
Range("A1").Select
ActiveWorkbook.SaveAs Filename:="/Users/LucasWayne/Desktop/Websales.txt", FileFormat:=xlText, CreateBackup:=False
Shell ("/Users/LucasWayne/Desktop/WebSalesToK4.app")
ActiveWorkbook.Close