excel - 使用 vba/excel 从 PDF 表单中获取“锁定”和“工具提示”值
问题描述
我想从 PDF 表单中获取“工具提示”值和“锁定”值,代码在没有标记行的情况下工作:
ActiveCell.Value = objField.Locked ''''' here is the problem, need the property name
该行在此函数内:
Sub getPDFFields()
'base code: http://myengineeringworld.net/2013/10/read-and-write-pdf-forms-from-excel-vba.html
'Declaring the necessary variables.
Dim strPDFPath As String
Dim objAcroApp As Object
Dim objAcroAVDoc As Object
Dim objAcroForm As Object
Dim objobjFields As Object
Dim objField As Object
'Specify the path of the sample PDF form.
'Using workbook path:
strPDFPath = ThisWorkbook.PATH & "\" & "ALL_Forms.pdf"
On Error Resume Next
'Initialize Acrobat by creating the App object.
Set objAcroApp = CreateObject("AcroExch.App")
'Check if the object was created.
If Err.Number <> 0 Then
MsgBox "Could not create the App object!", vbCritical, "Object error"
'Release the object and exit.
Set objAcroApp = Nothing
Exit Sub
End If
'Create the AVDoc object.
Set objAcroAVDoc = CreateObject("AcroExch.AVDoc")
'Check if the object was created.
If Err.Number <> 0 Then
MsgBox "Could not create the AVDoc object!", vbCritical, "Object error"
'Release the objects and exit.
Set objAcroAVDoc = Nothing
Set objAcroApp = Nothing
Exit Sub
End If
On Error GoTo 0
'Open the PDF file.
If objAcroAVDoc.Open(strPDFPath, "") = True Then
'Show the application.
objAcroApp.Show
On Error Resume Next
'Create the Acrobat Form object.
Set objAcroForm = CreateObject("AFormAut.App")
'Check if the object was created.
If Err.Number <> 0 Then
MsgBox "Could not create the AFormAutobject!", vbCritical, "Object error"
'Release the objects and exit.
Set objAcroAVDoc = Nothing
Set objAcroApp = Nothing
Exit Sub
End If
On Error GoTo 0
'Get the fields of the form.
Set objobjFields = objAcroForm.Fields
'Print the number of form fields.
'ActiveCell.Value = "Total form Fields = " & objobjFields.Count
'ActiveCell.OFFSET(1, 0).Select
i = 1
For Each objField In objobjFields
'Print the name of the fields, values and their type (if there are any).
'will print them in table like form starting at the active cell
ActiveCell.Value = objField.Name
ActiveCell.OFFSET(0, 1).Select
ActiveCell.Value = objField.Value
ActiveCell.OFFSET(0, 1).Select
ActiveCell.Value = objField.Type
ActiveCell.OFFSET(0, 1).Select
ActiveCell.Value = objField.Locked ''''' here is the problem, need the property name
ActiveCell.OFFSET(1, -3).Select
Next objField
Else
Debug.Print "Could not open the file!"
'Close the Acrobat application.
objAcroApp.Exit
'Release the objects and exit.
Set objAcroAVDoc = Nothing
Set objAcroApp = Nothing
Exit Sub
End If
'Close the form without saving the changes.
objAcroAVDoc.Close True
'Close the Acrobat application.
objAcroApp.Exit
'Release the objects.
Set objAcroPDDoc = Nothing
Set objField = Nothing
Set objobjFields = Nothing
Set objAcroForm = Nothing
Set objAcroAVDoc = Nothing
Set objAcroApp = Nothing
End Sub
我不确定如何获取 pdf 字段的“工具提示”或“锁定状态”?
解决方案
推荐阅读
- ansible - 在ansible中使用jinja2时如何避免临时文件
- java - 如何将 PostgreSQL 函数返回的 PgObject 值映射到自定义 java 对象
- python - 在 YouTube 上搜索并返回 n 个链接
- c# - “错误:TrustFailure(身份验证失败,请参阅内部异常。)”尝试调用 ASP.NET api 时
- excel - VBA:为什么代码无法识别 Excel 工作表的名称
- angular - 刷新 DOM 元素不能作为例外的 Angular 工作
- python-3.x - 如何使用 python 打开浏览器并连接到共享点?
- ios - 为什么我的matchedGeometryEffect 基于右下角移动?
- excel - Excel VBA 代码以使用桌面、MS Office SSO 登录到 Fusion SaaS SSO
- nodemailer - Nodemailer starter 示例连接 ETIMEDOUT 错误