复制,粘贴值,另存为"文件路径。仅适用于值大于1的工作表

时间:2015-07-09 22:02:09

标签: excel vba excel-vba

我正在尝试自动化流程。我们收到一份包含多家公司结算信息的报告。我们目前将此报告粘贴到Excel文档中,并筛选出每个单独公司的单个工作表。

我们有一个宏,可以将值复制,粘贴到新工作表并保存文件。问题是宏为excel文件中的每个工作表保存一个文件,我想调整宏,以便它只保存那个月有帐单信息的文件。

因此,我们不会保存新的工作表,也不会为客户收费。

目前,每个客户工作表的宏设置如下。

例如:' BGNBINS

Sheets("BGNBINS").Select
Cells.Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
Cells.Select
Cells.EntireColumn.AutoFit
Application.CutCopyMode = False
ActiveWindow.DisplayGridlines = False

'Save the new workbook and close it

ActiveWorkbook.SaveAs Filename:= _
    "G:\ACCTG RV\Breena's Admin & JDE\Weighbridge Reports (Breena)\3rd Party Tonnes\Customers 3rd Party\06.2015\BGNBINS 0615 WTS.xlsx" _
    , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close

' CONSOLW

Sheets("CONSOLW").Select
Cells.Select
Selection.Copy
Workbooks.Add

'Paste special values and formats

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

'resize to fit gridlines
    Cells.Select
Cells.EntireColumn.AutoFit
ActiveWindow.DisplayGridlines = False

Range("A1").Select
Application.CutCopyMode = False

'save and close file in specified drive and name

ActiveWorkbook.SaveAs Filename:= _
    "G:\ACCTG RV\Breena's Admin & JDE\Weighbridge Reports (Breena)\3rd Party Tonnes\Customers 3rd Party\06.2015\CONSOLW 0615 WTS.xlsx" _
    , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close

1 个答案:

答案 0 :(得分:0)

对不起,你对这张表的工作原理有点模糊,但这就是你的目标吗?

If ActiveSheet.Range("a1") > 0 Then
      'Save the new workbook and close it
      ActiveWorkbook.SaveAs Filename:="File Path", FileFormat:=xlOpenXMLWorkbook,   CreateBackup:=False
      ActiveWorkbook.Close
End If