如何从pdf复制数据并使用vba将其粘贴到excel中

时间:2017-09-27 07:56:51

标签: excel vba excel-vba copy

我已经尝试过这段代码,但它没有正常工作,请帮助我。

Sub Shell_Copy_Paste()

   Dim o As Variant
   Dim wkSheet As Worksheet

   Set wkSheet = ActiveSheet

   o = Shell("C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe C:\Users\saurabh.ad.sharma\Desktop\red.pdf", vbNormalFocus)

   Application.Wait (Now + TimeSerial(0, 0, 2)) 'Wait for Acrobat to load

   SendKeys "^a"   'Select All
   SendKeys "^c"   'Copy
   SendKeys "%{F4}"    'Close shell application

   wkSheet.Range("B5").Select
   SendKeys "^v"   'Paste

End Sub

请用这个

指出错误和我

1 个答案:

答案 0 :(得分:0)

最好不要对宏进行硬编码。下面的代码将允许您选择所需的文件,因此打开PDF文件时不会有任何问题。

Sub run()


Dim fn As String

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
If .Show = -1 Then
fn = .SelectedItems(1)
Else
MsgBox "You cancel the process."
Exit Sub
End If
End With

End Sub