从PDF复制数据后Excel运行时错误1004

时间:2018-09-13 12:38:15

标签: excel runtime-error

我正在从PDF文件中提取文件并将其粘贴到Excel中,效果很好。尝试处理提取的数据时,我不断收到“运行时错误1004”

我的代码如下

Sub PDF_Upload()
    Dim objWord As Object
    Dim objDoc As Object
    Dim wdFileName
    Dim LastRow As Long
    Dim fso As New FileSystemObject
    Dim fileName As String

    fileName = fso.GetFileName("C:\ABC.pdf")
    Title = Replace(fileName, ".pdf", "")

    Set objWord = CreateObject("word.Application")
    wdFileName = "C:\ABC.pdf"

    Set objDoc = objWord.Documents.Open(wdFileName)
    objWord.Selection.WholeStory
    objWord.Selection.Copy

    ' create new sheet and call it the pdf name
    Sheets.Add
    ActiveSheet.name = Title
    [A1].Select
    ActiveSheet.Paste

    ' Close Word
    objDoc.Close SaveChanges:=False
    objWord.Quit
    Application.DisplayAlerts = True

    ' check
    Sheets(Title).Select
    ' process fails in the next line
    LastRow = ActiveSheet.Range("A1").Offset(ActiveSheet.Rows.Count - 1, 0).End(xlUp).Row
End Sub

一切正常,直到我到达最后一行“ LastRow = ActiveSheet ....”

关于导致错误的原因的任何想法。我在StackOverflow(123,...)中查看了有关1004错误的其他帖子,但找不到任何有帮助的东西。

0 个答案:

没有答案