本文介绍了运行时错误低于代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Sub InvoiceReport()
Dim myFile As String, lastRow As Long
myFile = "C:\Users\iaquino\Documents\Invoices\" & _
Sheets("Invoice").Range("A10") & "_" & _
Sheets("Invoice").Range("F4") & _
Format(Now(), "yyy-mm-dd") & ".pdf"
lastRow = Sheets("Invoice File").UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
'Transfer data to Invoice File
Sheets("Invoice File").Cells(lastRow, 1) = Sheets("Invoice").Range("A10")
Sheets("Invoice File").Cells(lastRow, 2) = Sheets("Invoice").Range("F4")
Sheets("Invoice File").Cells(lastRow, 3) = Sheets("Invoice").Range("F28")
Sheets("Invoice File").Cells(lastRow, 4) = Now
Sheets("Invoice File").Hyperlinks.Add Anchor:=Sheets("Invoice File").Cells(lastRow, 5), Address:=myFile, TextToDisplay:=myFile
'Create invoice in PDF format
Sheets("Invoice").ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFile
Application.DisplayAlerts = False
'create invoice in XLSX format
ActiveWorkbook.SaveAs "C:\Users\iaquino\Documents\invoices\" & _
Sheets("Sheet1").Range("A10") & "_" & _
Sheets("Invoice").Range("F4") & "_" & _
Format(Now(), "yyy-mm-dd") & "xlsx", FileFormat:=51
Application.DisplayAlerts = True
End Sub
调试错误: -
运行时错误'5'
表格(发票)。ExportAsFixedFormat类型:= xlTypePDF,文件名:= myFile
Application.DisplayAlerts = False
我的尝试:
Plz紧急解决这个问题。
Error debug:-
Run time error '5'
Sheets("Invoice").ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFile
Application.DisplayAlerts = False
What I have tried:
Plz give urgent solution this problem.
推荐答案
lastRow = Sheets("Invoice File").UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
可以简化为
can be simplified to
lastRow = Sheets("Invoice File").UsedRange.RowS.Count + 1
这篇关于运行时错误低于代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!