Voglio passare avanti e indietro tra l'applicazione con il comando shell in VBA. Sto usando SendKeys per fare cose nel processo A quindi passare al processo B, quindi per elaborare A, quindi elaborare B. Funziona perfettamente per la prima iterazione. Quando uso AppActivate per tornare al processo B, in realtà passa a focus focus sul processo B. TUTTAVIA, ignora i comandi successivi da SendKeys.Utilizzo di AppActivate e Sendkeys nel comando shell VBA
codiceEsempio:
Sub pastePDF2TXT_v3(pdfName As String, txtName As String)
Dim acrobatID
Dim acrobatInvokeCmd As String
Dim acrobatLocation As String
Dim notepadID
Dim acrobatID2
Dim notepadID2
Debug.Print "here"
acrobatLocation = "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe"
acrobatInvokeCmd = acrobatLocation & " " & pdfName
acrobatID = Shell(acrobatInvokeCmd, 1)
AppActivate acrobatID
SendKeys "^a", True '^A selects everything already in the pdf file.
SendKeys "^c", True '^C copies the selection to the clipboard.
notepadID = Shell("NOTEPAD.EXE " & txtName, 1) ' invoke notepad on the text file.
AppActivate notepadID ' set the new app as teh active task.
SendKeys "^a", True '^A selects everything already in the text file.
SendKeys "^v", True '^V pastes the new stuff over the top of the old text file (deleting the old stuff)
SendKeys "%{END}", True ' makre sure last line of text file
SendKeys "{ENTER}", True
AppActivate acrobatID ' NOTE: APPEARS TO WORK UP TO THIS POINT.
SendKeys "{ENTER}", True ' NOTE: SECOND APP IGNORES SUBSEQUENT COMMANDS FROM HERE DOWN.
SendKeys "^a", True '^A selects everything already in the pdf file.
SendKeys "^c", True '^C copies the selection to the clipboard.
SendKeys "%f", True 'alt f, x to exit Notepad.exe
SendKeys "x", True
'acrobatID.Quit
Debug.Print "start second"
AppActivate notepadID ' set the new app as teh active task.
SendKeys "%{END}", True 'Go to end of text file.
SendKeys "^v", True '^V pastes the new stuff at end of file.
SendKeys "{ENTER}", True
SendKeys "^s", True
SendKeys "%f", True 'alt f, x to exit Notepad.exe
SendKeys "x", True
notepadID.Quit
acrobatID.Quit
End Sub
Quello che ho è un gruppo (più di 1000) di file PDF che hanno il testo che voglio analizzare. Parte del testo è in forma libera e inutilizzabile. Altre parti del testo sono formattate in modo abbastanza coerente e posso ottenere tali informazioni e inserirle in un database (foglio di calcolo Excel) per analisi successive. Dopo che i dati sono stati inseriti in un file di testo, analizzo uno script perl per ottenere le cose che voglio e creare un CSV. Questo è un modo schifoso di farlo - per i motivi che offri, anche perché è esteticamente brutto e non sembra funzionare in modo coerente in tutti i casi. – elbillaf
Il metodo generale funziona se il pdf è solo una pagina, ma per pagine multiple, acrobat seleziona solo una pagina su un^A (da sendkeys) quindi devo andare avanti e indietro - che non sembra funzionare. Sono stato in grado di aggirare questo problema per il mio compito attuale, ma mi piacerebbe un metodo generale per affrontare questo tipo di problema in modo che i metodi futuri non siano così irritanti. – elbillaf
Si può usare qualcosa come http://www.pdf2txt.com/ invece di provare ad automatizzare la GUI di Acrobat? –