-- Requires AppleScript Toolbox for click support-- Acrobat and Excel are open at execution time-- The script is complicated by the fact that this particular PDF form has a different number of rows on the first page than every subsequent pagesetcolumnLettersto{"A","C","D","E","F"}setcurrentPageto1setpagebreakCountFirstto17setpagebreakCountSubsequentto18setpagebreakExtraTabsto2setrowCounttogetRowCount()setcurrentRowto1-- Create the corresponding number of field rows in Acrobatactivateapplication"Adobe Acrobat Reader DC"tellapplication"System Events"totellprocess"Adobe Acrobat Reader DC"repeatrowCounttimesASTclickat{140,311}setcurrentRowto(currentRow+1)endrepeatendtell-- Tab back to the starting fieldtellapplication"System Events"totellprocess"Adobe Acrobat Reader DC"repeat3timeskeystroketabendrepeatendtellsetcurrentRowto1-- Iterate over Excel rowsrepeatrowCounttimesrepeatwithcurrentLetterincolumnLetters-- Copy value from Exceltellapplication"Microsoft Excel"setcurrentCelltocurrentLetter¤tRowas stringset the clipboard tovalueofcellcurrentCellas stringendtell-- Paste value into Acrobat and tab to next fieldactivateapplication"Adobe Acrobat Reader DC"tellapplication"System Events"totellprocess"Adobe Acrobat Reader DC"keystroke"v"usingcommanddown-- Corrects for issue with keypresses occurring too quicklydelay0.1keystroketabendtellendrepeatifcurrentRowis greater than1thenifcurrentPageis equalto1thensetpagebreakCounttopagebreakCountFirstsetpagebreakModto0elseifcurrentRow>pagebreakCountSubsequentthensetpagebreakCounttopagebreakCountSubsequentsetpagebreakModto(pagebreakCountSubsequent-1)elsesetpagebreakCounttofalseendifif(pagebreakCountis notfalse)and((currentRowmodpagebreakCount)is equaltopagebreakMod)thenrepeatpagebreakExtraTabstimestellapplication"System Events"totellprocess"Adobe Acrobat Reader DC"keystroketabendtellendrepeat-- Increment page counter to help with determining page breaks more easilysetcurrentPageto(currentPage+1)endifendif-- Two extra tabs to get to next set of fieldsrepeat2timestellapplication"System Events"totellprocess"Adobe Acrobat Reader DC"keystroketabendtellendrepeatsetcurrentRowto(currentRow+1)endrepeat-- From http://www.cubemg.com/how-to-get-the-number-of-rows-inan-excel-spreadsheet-with-applescript/togetRowCount()tellapplication"Microsoft Excel"tellactivesheettellusedrangesetrctocountofrowsendtellreturnrcendtellendtellendgetRowCount
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.