Object不支持此属性或方法错误

时间:2018-01-29 13:29:37

标签: vba excel-vba pdf excel

我试图将数据从excel复制到易错的PDF表单。使用下面的代码,我打开错误的表单并填充数据,我需要使用varibale' pr' 。 保存时会导致运行时错误

  

"对象不支持此属性或方法"

Dim fcount As Long
Dim sFieldName As String

Set AcrobatApplication = CreateObject("AcroExch.App")
Set AcrobatDocument = CreateObject("AcroExch.AVDoc")

If AcrobatDocument.Open("C:\Users\Desktop\Projects\Jan 2018\Excel to PDF\Test.pdf", "") Then
    AcrobatApplication.Show
    Set AcroForm = CreateObject("AFormAut.App")
    Set Fields = AcroForm.Fields
    fcount = Fields.Count    ' Number of Fields

    With ThisWorkbook.Sheets(1)
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For i = 2 To LastRow
            Fields("Enter county name").Value = Range("A" & i).Value
            Fields("Enter county served").Value = Range("B" & i).Value
            Fields("Parcel number").Value = Range("C" & i).Value
            pr = Range("C" & i).Value
            Fields("Property owner name").Value = Range("D" & i).Value

            fname = "C:\Users\Desktop\Projects\Jan 2018\Excel to PDF\docs\" & pr & ".pdf"

            If AcrobatDocument.Save(PDSaveFull, fname) = False Then
                MsgBox ("Cannot save the modified document")

            End If

        Next
    End With

Else
    MsgBox "failure"

1 个答案:

答案 0 :(得分:0)

Dim pr as String

考虑到你只在这里使用它,

应该足够了:

fname = "C:\Users\Desktop\Projects\Jan 2018\Excel to PDF\docs\" & pr & ".pdf"