运行时错误:VBA的1004 [英] Run time Error: 1004 of VBA

查看:92
本文介绍了运行时错误:VBA的1004的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到错误是什么以及如何纠正错误?

  Sub  InvoiceReport()
Dim myFile 作为 字符串,lastRow As
myFile = C:\\ \\ Users\iaquino \Documents\Invoices\&表格( Invoice)。范围( A10)& _&表格( Invoice)。范围( F4)&格式(Now(), yyy-mm-dd)& 。pdf
lastRow = Sheets( 发票文件)。UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
' 将数据传输到发票文件
表格( 发票文件)。单元格(lastRow, 1 )=表格(< span class =code-string> Invoice)。范围( < span class =code-string> A10)
Sheets( Invoice File )。单元格(lastRow, 2 )=表格( Invoice)。范围( F4
表格( 发票文件)。单元格(lastRow, 3 )=表格( 发票)。范围( F28
表格( 发票文件)。单元格(lastRow, 4 )=现在
表格( 发票文件)。Hyperlinks.Add Anchor:= Sheets( 发票文件)。单元格(lastRow, 5 ),地址:= myFile,TextToDisplay:= myFile
' 以PDF格式创建发票
表格( Invoice)。ExportAsFixedFormat类型:= xlTypePDF,文件名:= myFile
Application.D isplayAlerts = False
' 在XLSX中创建发票格式
ActiveWorkbook.SaveAs C:\ Users \iaquino \Documents \发票\&表格( Sheet1)。范围( A10)& _&表格( Invoice)。范围( F4)& _&格式(Now(), yyy-mm-dd)& xlsx,FileFormat:= 51
Application.DisplayAlerts = True







结束 Sub

解决方案

可能的原因很少1004运行时错误,但最重要的是:你无法在Excel应用程序中打开pdf!结论:你无法从pdf文件中读取!



初看:

1)源文件尚未打开,

2)您没有设置对工作簿(源文件)的引用,

3)工作表不存在或者有两个或多个打开的文件具有相同的工作表名称。



如需了解更多信息,请参阅:处理VBA中的运行时错误 [ ^ ]

I am having trouble find what the error is and how to correct it?

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

解决方案

There's few possible reasons of 1004 run-time error, but the most important is: you cannot open pdf in Excel application! Conclusion: you cannot read from pdf file!

On the first look:
1) source file hasn't been opened,
2) you did not set reference to a workbook (source file),
3) sheet does not exists or there are two or more opened files with the same sheet's name.

For further information, please see: Handle Run-Time Errors in VBA[^]


这篇关于运行时错误:VBA的1004的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆