Exel into Adobe

HappyChappy

Active Member
Joined
Jan 26, 2013
Messages
384
Office Version
  1. 2019
  2. 2010
  3. 2007
Platform
  1. Windows
i have driving license numbers in excel but in adobe the fields are setup as single cells can i paste into the first cell and it populate all the others without doing each letter/number individually.
any help please as its very time consuming and open to user error while inputting.
 

Attachments

  • Screenshot 2024-12-07 102029.png
    Screenshot 2024-12-07 102029.png
    25.7 KB · Views: 22

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
As a proof of concept, see if this code works for you. It uses the UI Automation library to set the value of the first field in the currently open PDF (e.g. the Forename field) and saves the PDF. This field must be an Edit control - use Accessibility Insights to determine whether it is an Edit control or not.

This screenshot shows the Forename input field in my test PDF form is an Edit control.

1734195436460.png



For the code to compile and run you must set a reference to UIAutomationClient, via Tools -> References in the VBA editor.

Module1 - the main routine which gets the currently open .pdf file and passes the string "MrExcel" to the UIAutomation routine.

VBA Code:
Option Explicit

Public Sub Fill_PDF_Form_Field()
    
    #If VBA7 Then
        Dim AcrobatHwnd As LongPtr
    #Else
        Dim AcrobatHwnd As Long
    #End If
    Dim PDFwindowTitle As String
            
    Get_Acrobat_Window AcrobatHwnd, PDFwindowTitle
    
    If AcrobatHwnd <> 0 Then
        Debug.Print "PDF window title = " & PDFwindowTitle
        UIAutomation_Fill_First_Form_Field AcrobatHwnd, "MrExcel"
    Else
        MsgBox "A PDF is not currently open", vbExclamation
    End If

End Sub

Module2 - contains the UIAutomation code.

VBA Code:
Option Explicit

#If VBA7 Then
    Private Declare PtrSafe Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
#Else
    Private Declare Sub Sleep Lib "kernel32.dll" Alias "Sleep" (ByVal dwMilliseconds As Long)
#End If

#If VBA7 Then
Public Sub UIAutomation_Fill_First_Form_Field(AcrobatHwnd As LongPtr, fieldValue As String)
#Else
Public Sub UIAutomation_Fill_First_Form_Field(AcrobatHwnd As LongPtr, fieldValue As String)
#End If
   
    Dim UIAuto As IUIAutomation
    Dim AcrobatMain As IUIAutomationElement
    Dim ControlTypeCond As IUIAutomationCondition
    Dim Document As IUIAutomationElement
    Dim Fields As IUIAutomationElementArray
    Dim field As IUIAutomationElement
    Dim i As Long
    
    'Create UIAutomation object
    
    Set UIAuto = New CUIAutomation
    
    'Get the main Acrobat window of the displayed PDF.  This is a Window control with the class name AcrobatSDIWindow
    
    Set AcrobatMain = UIAuto.ElementFromHandle(ByVal AcrobatHwnd)
    
    'Get the main document control
    'ControlType = UIA_DocumentControlTypeId (0xC36E) 50030
    
    Set ControlTypeCond = UIAuto.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_DocumentControlTypeId)
    Do
        Set Document = AcrobatMain.FindFirst(TreeScope_Descendants, ControlTypeCond)
        DoEvents
        Sleep 200
    Loop While Document Is Nothing
    
    'Get all Edit controls within the document
    'ControlType:    UIA_EditControlTypeId (0xC354)
    
    Set ControlTypeCond = UIAuto.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_EditControlTypeId)
    Set Fields = Document.FindAll(TreeScope_Subtree, ControlTypeCond)
    Debug.Print Fields.Length   'includes read-only fields
    Sleep 200
    
    'Fill the first Edit control field which isn't read-only
    
    i = 0
    Do While i < Fields.Length - 1
        Set field = Fields.GetElement(i)
        If Not field.GetCurrentPropertyValue(UIA_ValueIsReadOnlyPropertyId) Then
            field.SetFocus
            SendKeys "^a{DELETE}", True 'clear any existing field value
            Sleep 100
            DoEvents
            SendKeys fieldValue
            DoEvents
            Sleep 100
            Exit Do
        End If
        i = i + 1
    Loop
    
    'Ctrl+S to save the modified PDF
    
    AcrobatMain.SetFocus
    SendKeys "^(s)", True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,620
Messages
6,179,927
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top