简体   繁体   English

使用VBA将数据从pdf提取到Excel

[英]Pulling data from pdf to Excel using VBA

I have a more than 1000 pdf files and I want to extract/pull data from pdf.我有超过 1000 个 pdf 文件,我想从 pdf 中提取/拉取数据。 If I use the pdf to excel conversion then it will take long time so I am trying pull data from pdf to excel using vba.如果我使用 pdf 到 excel 的转换,那么这将花费很长时间,所以我正在尝试使用 vba 将数据从 pdf 提取到 excel。

The format in PDF are as follows: Year 20XX Month MAR PDF 格式如下: 年 20XX 月 MAR

Unique Identification Number(UIN) Name of the Company公司的唯一标识号 (UIN) 名称

Particulars Value IncomeTax IndirectTax OtheTaxes Sales 20000 1000 10000 500 Purchases 20000 500 500 0 Exempt 3000 0 0 0详情 价值 IncomeTax IndirectTax OtheTaxes 销售 20000 1000 10000 500 采购 20000 500 500 0 豁免 3000 0 0 0

The format in which I require in Excel is as follows:我在Excel中要求的格式如下:

Year Month UIN NameofthCompany Particularss Value IncomeTax Indirect OtherTaxes年月 UIN NameofthCompany Particulars Value IncomeTax Indirect OtherTaxes

There are tools online that do this for you.有在线工具可以为您执行此操作。 Also, if you want to consider converting all PDF files in a folder to text files, you can easily import text all text files into a folder into Excel, and then manipulate any way you want.另外,如果您想考虑将一个文件夹中的所有 PDF 文件转换为文本文件,您可以轻松地将一个文件夹中的所有文本文件导入 Excel,然后以任何您想要的方式进行操作。 A PDF file is essentially a text file, on steroids.一个 PDF 文件本质上是一个文本文件,在类固醇上。 Post back if you have additional questions.如果您有其他问题,请发回。

How to import multiple text files from a folder into one worksheet?如何将文件夹中的多个文本文件导入到一个工作表中?

Sub Test()
'UpdatebyExtendoffice6/7/2016
    Dim xWb As Workbook
    Dim xToBook As Workbook
    Dim xStrPath As String
    Dim xFileDialog As FileDialog
    Dim xFile As String
    Dim xFiles As New Collection
    Dim I As Long
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a folder [Kutools for Excel]"
    If xFileDialog.Show = -1 Then
        xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then Exit Sub
    If Right(xStrPath, 1) <> "\" Then xStrPath = xStrPath & "\"
    xFile = Dir(xStrPath & "*.txt")
    If xFile = "" Then
        MsgBox "No files found", vbInformation, "Kutools for Excel"
        Exit Sub
    End If
    Do While xFile <> ""
        xFiles.Add xFile, xFile
        xFile = Dir()
    Loop
    Set xToBook = ThisWorkbook
    If xFiles.Count > 0 Then
        For I = 1 To xFiles.Count
            Set xWb = Workbooks.Open(xStrPath & xFiles.Item(I))
            xWb.Worksheets(1).Copy after:=xToBook.Sheets(xToBook.Sheets.Count)
            On Error Resume Next
            ActiveSheet.Name = xWb.Name
            On Error GoTo 0
            xWb.Close False
        Next
    End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM