use*_*358 5 excel acrobat vba excel-vba isnumeric
我运行一个宏,该宏从PDF文件复制表格并将其保存在Excel中。一些表包含空单元格,在我的分析中,我需要知道空单元格的数量。我有一个遍历每一列的函数,以检查该单元格中的值是否为数字。麻烦的是,当我在一个空单元格上运行此函数时,它返回true。我什至尝试使用Isblank()函数手动检查单元格,它返回“ false”。(如果我在粘贴范围之外的任何单元格上尝试此操作,它将返回“ true”)
我猜想当我从PDF复制并粘贴内容时,它会以某种方式为空白单元格粘贴一些值。
有没有人遇到过类似的问题?如果是这样,关于如何解决的任何想法?
如果有帮助,这是我用来复制和粘贴的代码
'Initialize Acrobat by creating App object
Set PDFApp = CreateObject("AcroExch.App")
'Set AVDoc object
Set PDFDoc = CreateObject("AcroExch.AVDoc")
'Open the PDF
If PDFDoc.Open(PDFPath, "") = True Then
PDFDoc.BringToFront
'Maximize the document
Call PDFDoc.Maximize(True)
Set PDFPageView = PDFDoc.GetAVPageView()
'Go to the desired page
'The first page is 0
Call PDFPageView.GoTo(DisplayPage - 1)
'-------------
'ZOOM options
'-------------
'0 = AVZoomNoVary
'1 = AVZoomFitPage
'2 = AVZoomFitWidth
'3 = AVZoomFitHeight
'4 = AVZoomFitVisibleWidth
'5 = AVZoomPreferred
'Set the page view of the pdf
Call PDFPageView.ZoomTo(2, 50)
End If
Set PDFApp = Nothing
Set PDFDoc = Nothing
On Error Resume Next
'Show the adobe application
PDFApp.Show
'Set the focus to adobe acrobat pro
AppActivate "Adobe Acrobat Pro"
'Select All Data In The PDF File's Active Page
SendKeys ("^a"), True
'Right-Click Mouse
SendKeys ("+{F10}"), True
'Copy Data As Table
SendKeys ("c"), True
'Minimize Adobe Window
SendKeys ("%n"), True
'Select Next Paste Cell
Range("A" & Range("A1").SpecialCells(xlLastCell).Row).Select
'Cells(1, 1).Select
'Paste Data In This Workbook's Worksheet
ActiveSheet.Paste
Run Code Online (Sandbox Code Playgroud)
小智 5
在某些情况下,最好检查单元格内字符的长度而不是使用isNumeric(), 或检查错误等...
例如尝试下面的代码
它建立活动工作表中使用的范围,然后通过检查每个单元格的长度 (len()) 进行迭代
您可以在 VBE 中查看Immediate Window CTRL+G以查看哪些单元格地址为空 或 等到宏执行完成后,您将收到一个消息框,说明该范围内有多少个空单元格
Option Explicit
Sub CheckForEmptyCells()
Dim lastCol As Range
Set lastCol = ActiveSheet.Cells.Find(What:="*", After:=ActiveSheet.Cells(1, 1), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
Dim rng As Range
Set rng = Range("A1:" & lastCol.Address)
Dim cnt As Long
cnt = 0
Dim cell As Range
For Each cell In rng
If Len(cell) < 1 Then
Debug.Print cell.Address
cnt = cnt + 1
End If
Next
MsgBox "there are " & cnt & " empty cells within the range " & rng.Address
End Sub
Run Code Online (Sandbox Code Playgroud)
