【问题标题】:VBA: convert to pdf script that ignores blank cells in the conversionVBA:转换为忽略转换中的空白单元格的 pdf 脚本
【发布时间】:2016-12-29 07:43:03
【问题描述】:

我有一个将工作表“ConversiePDF”转换为 PDF 的 vba 代码。
问题是整个工作表是由公式生成的,并且工作表的一半正在填充数据,而另一半保持空白(公式正在运行但返回“”

我的代码将整个工作表转换到第 1000 行并生成 32 页(女巫 30 是空的 - 只是没有实际数据的表)

如果从 A 到 Q 的整行为空或返回“”,我需要它忽略公式返回“”的空白单元格。 (如果一行中只有一两个或三个单元格是空的,则不适用)

请帮忙..

'This is my code till now: 

Dim ThisRng As Range
Dim strfile As String
Dim myfile As Variant

'Selectie Sheet pentru conversie
With ActiveWorkbook.Sheets("ConversiePDF")
Set ThisRng = .Range("A2", .Cells(.Rows.Count, "F").End(xlUp))
End With

谢谢你..

【问题讨论】:

  • 您是否尝试过可以手动设置或通过 VBA 代码设置的过滤器(出空行)?您不必检查所有列,可能检查一列就足以确定行是否为空。您还可以检查 SUM()COUNT()(或其他 COUNT 公式,具体取决于您拥有的数据类型)结果并确定行是否为空并将其隐藏。
  • 我检查了 excel 过滤器,它可以工作。仅将剩余单元格转换为 pdf,但我需要在 vba 中使用它来自动执行此操作。我在互联网上检查正确的代码,但找不到我可以集成的东西(可能是因为我对 vba 比较白痴)
  • 好的。我设法获得以下代码,仅将具有值的单元格转换为 PDF,但它也删除了从工作表返回“”的公式。我需要这些公式(永久)保留在工作表中,但如果 "" 则不会显示在 pdf 中;
    代码:Selection.AutoFilter Selection.AutoFilter Field:=1, Criteria1:="" 'column A Selection.AutoFilter Field:=5, Criteria1:="" 'column E

标签: excel vba


【解决方案1】:
Private Sub CommandButton1_Click()
'BUTON CONVERSIE PDF - ANGAJATORI
'DESCRIPTION: CONVERSIE A UNUI SHEET IN PDF
Dim ThisRng As Range
Dim strfile As String
Dim myfile As Variant


'Selectie Sheet pentru conversie
Application.ScreenUpdating = False
ActiveWorkbook.Sheets("PDF ANG").Visible = True

'Selectie filtru pentru ce sa converteasca
ActiveWorkbook.Sheets("PDF ANG").Select
Selection.AutoFilter Field:=1, Criteria1:="<>" 'column A
Selection.AutoFilter Field:=5, Criteria1:="<>" 'column E

'Selectie raza pentru conversie
With ActiveWorkbook.Sheets("PDF ANG")
Set ThisRng = .Range("A2", .Cells(.Rows.Count, "F").End(xlUp))
End With

'Prompt for save location
strfile = "Selection" & "_" _
& Format(Now(), "yyyymmdd_hhmmss") _
& ".pdf"
strfile = ThisWorkbook.Path & "\" & strfile
myfile = Application.GetSaveAsFilename _
(InitialFileName:=strfile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and File Name to Save as PDF")
If myfile <> "False" Then 'save as PDF
ThisRng.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
myfile, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Else
MsgBox "No File Selected. PDF will not be saved", vbOKOnly, "No File Selected"
End If
ActiveWorkbook.Sheets("PDF ANG").ShowAllData
ActiveWorkbook.Sheets("PDF ANG").Visible = False

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-07
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 2021-07-15
    • 2015-12-27
    相关资源
    最近更新 更多