Excel无法使用可用资源完成此任务。选择较少数据或关闭其他应用程序。 ActiveWorkbook.SaveAs

时间:2016-01-25 13:51:20

标签: excel vba excel-vba

我在Excel 2010或更高版本上运行以下VBA代码时遇到问题,而它在Excel XP上运行得很好。在更高版本中,带有文本“Excel的消息框无法使用可用资源完成此任务。选择较少的数据或关闭其他应用程序”。出现,并在单击“确定”时,Excel重新启动。

代码:

Sub Calibrar()

    Dim PDFFile As String
    Dim XLSFile As String

    Application.ScreenUpdating = False
    Worksheets("Agendamento").Activate

    XLSFile = Range("W17") & "_" & Range("W19") & "_" & Range("E23") & "_" & "Agendamento" & ".xls"

    ActiveWorkbook.SaveAs Filename:="\\PMPA-FS3\DMAE-LabHid-Calibra-Agendamento$\Solicitações\" & Range("W17") & "_" & Range("W19") & "_" & Range("E23") & "_Agendamento" & ".xls"

    PDFFile = Range("W17") & "_" & Range("W19") & "_" & Range("E23") & "_" & Range("E11") & "_" & "Pedido" & ".xls"

    Worksheets("Agendamento").Activate

    Worksheets("Agendamento").Move

    ActiveWorkbook.SaveAs Filename:="\\PMPA-FS3\DMAE-LabHid-Calibra-Agendamento$\Pedidos\" & Range("W17") & "_" & Range("W19") & "_" & Range("E23") & "_" & Range("E11") & "_" & "Pedido" & ".xls"

    Worksheets.PrintOut Preview:=False, Copies:=1, ActivePrinter:="CutePDF Writer on CPW2:", PrToFileName:="", Collate:=False

    Workbooks(XLSFile).Activate

    Worksheets("Controle").Activate

    Workbooks(XLSFile).Sheets("Controle").Move After:=Workbooks(PDFFile).Sheets(1)

    Workbooks(XLSFile).Activate

    Worksheets("Análise Crítica").Activate

    ActiveWorkbook.SaveAs Filename:="\\PMPA-FS3\DMAE-LabHid-Calibra-AnaliseCritica$\" & Range("W15") & "_" & Range("W16") & "_" & Range("E20") & "_Analise Critica" & ".xls"

    ActiveWorkbook.Close Savechanges:=True
    ActiveWorkbook.Close Savechanges:=True

End Sub

当我运行它时,所有文件都是正常生成的,但是消息和重启Excel非常烦人。

(编辑:我忘了提到我用任务管理器运行这个宏来查看使用了多少内存,我看不到任何过度消耗。)

关于我如何解决此问题的任何想法?

谢谢!

1 个答案:

答案 0 :(得分:0)

我遵循了@ScottHoltzman和@JMichael的建议,并将我的代码更改为:

Sub Calibrar()
'
' Calibrar Macro
' Macro gravada em 20/04/2012 por Lahidro
'
' Atalho do teclado: Ctrl+Shift+P
' Calibrar Macro
' Salva o Pedido de Agendamento da Calibração com a notação Processo+Ramal+hidrometro
'
' Atalho do teclado: Ctrl+Shift+P
'
    Dim PDFFile As String
    Dim XLSFile As String
    Dim processo As String
    Dim ramal As String
    Dim medidor As String
    Dim situacaoPedido As String

    Application.ScreenUpdating = False
    Set planilha = Workbooks("Mod.10.066_Agendamento de Ensaio de Medidor e Planilhas Associadas (revisão 2015.12.04).xls")
    processo = planilha.Worksheets("Agendamento").Range("W17").Value
    ramal = planilha.Worksheets("Agendamento").Range("W19").Value
    medidor = planilha.Worksheets("Agendamento").Range("E23").Value
    situacaoPedido = planilha.Worksheets("Agendamento").Range("E11").Value

    XLSFile = processo & "_" & ramal & "_" & medidor & "_" & "Agendamento" & ".xls"
    planilha.SaveAs Filename:="\\PMPA-FS3\DMAE-LabHid-Calibra-Agendamento$\Solicitações\" & processo & "_" & ramal & "_" & medidor & "_Agendamento" & ".xls"

    PDFFile = processo & "_" & ramal & "_" & medidor & "_" & situacaoPedido & "_" & "Pedido" & ".xls"

    planilha.Worksheets("Agendamento").Move
    ActiveWorkbook.SaveAs Filename:="\\PMPA-FS3\DMAE-LabHid-Calibra-Agendamento$\Pedidos\" & processo & "_" & ramal & "_" & medidor & "_" & situacaoPedido & "_" & "Pedido" & ".xls"
    Worksheets.PrintOut Preview:=False, Copies:=1, ActivePrinter:="CutePDF Writer on CPW2:", PrToFileName:="", Collate:=False

    Workbooks(XLSFile).Sheets("Controle").Move After:=Workbooks(PDFFile).Sheets(1)
    planilha.SaveAs Filename:="\\PMPA-FS3\DMAE-LabHid-Calibra-AnaliseCritica$\" & processo & "_" & ramal & "_" & medidor & "_Analise Critica" & ".xls"
End Sub

它有效。非常感谢你!