ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Users\UserName\Documents\FileName.pdf", Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False不提示正在发布
时间: 2023-05-17 19:02:56 浏览: 99
这是一个 VBA 代码,用于将当前活动的 Excel 工作表导出为 PDF 文件,保存在指定的文件路径下。其中,Quality 参数指定导出的 PDF 文件质量,IncludeDocProperties 参数指定是否包含文档属性,IgnorePrintAreas 参数指定是否忽略打印区域,OpenAfterPublish 参数指定是否在导出后打开 PDF 文件。如果设置为 False,则不会提示正在发布。
相关问题
VBA ExportAsFixedFormat Type:=xlTypePDF如何最快速
地将Excel文件转换为PDF格式?
您可以使用以下代码:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\UserName\Documents\FileName.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
其中,"ActiveSheet"是您要转换的工作表,"Filename"是您要保存的PDF文件的路径和名称。
Dim ws As Worksheet Dim lastRow As Long Set ws = ThisWorkbook.Worksheets("Sheet1") '清除格式和删除行列 ws.Cells.ClearFormats ws.Range("1:2").Delete Shift:=xlUp ws.Range("A:A,B:B,C:C,F:F,G:G,I:I,J:J,K:K,M:M,P:P,Q:Q,S:S,T:T").Delete Shift:=xlToLeft '添加新列 ws.Range("H1").Value = "回收时间" ws.Range("K1").Value = "回收人" ws.Range("L1").Value = "复核人" ws.Columns("E:E").Copy Destination:=ws.Columns("I:I") ws.Columns("F:F").Copy Destination:=ws.Columns("J:J") '筛选数据 ws.Range("A:D").AutoFilter ws.Range("A:D").AutoFilter Field:=1, Criteria1:="<>tt", VisibleDropDown:=False ws.Range("A:D").AutoFilter Field:=2, Criteria1:="<>996999", VisibleDropDown:=False ws.Range("A:D").AutoFilter Field:=3, Criteria1:="<>996999", VisibleDropDown:=False ws.Range("A:D").AutoFilter Field:=4, Criteria1:="<>*贴", Operator:=xlAnd, Criteria2:="<>*片", VisibleDropDown:=False '排序数据 With ws.Sort .SortFields.Clear .SortFields.Add2 Key:=ws.Range("A2:A500"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal .SetRange ws.Range("A1:L500") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With With ActiveSheet .Columns.AutoFit .Rows.AutoFit .Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove .Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove .Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove End With '合并单元格 With ws.Range("A1:L1") .Merge .Value = "yyy" End With '调整列宽 ws.Columns("B:B").ColumnWidth = 7.5 ws.Columns("E:E,I:I").ColumnWidth = 3.08 End Sub 改进
Sub UpdateData()
Dim ws As Worksheet
Dim lastRow As Long
Set ws = ThisWorkbook.Worksheets("Sheet1")
'清除格式和删除行列
With ws
.Cells.ClearFormats
.Range("1:2").Delete Shift:=xlUp
.Range("A:A,B:B,C:C,F:F,G:G,I:I,J:J,K:K,M:M,P:P,Q:Q,S:S,T:T").Delete Shift:=xlToLeft
'添加新列
.Range("H1").Value = "回收时间"
.Range("K1").Value = "回收人"
.Range("L1").Value = "复核人"
'复制列
.Columns("E:E").Copy Destination:=.Columns("I:I")
.Columns("F:F").Copy Destination:=.Columns("J:J")
'筛选数据
.Range("A:D").AutoFilter
.Range("A:D").AutoFilter Field:=1, Criteria1:="<>tt", VisibleDropDown:=False
.Range("A:D").AutoFilter Field:=2, Criteria1:="<>996999", VisibleDropDown:=False
.Range("A:D").AutoFilter Field:=3, Criteria1:="<>996999", VisibleDropDown:=False
.Range("A:D").AutoFilter Field:=4, Criteria1:="<>*贴", Operator:=xlAnd, Criteria2:="<>*片", VisibleDropDown:=False
'排序数据
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
With .Sort
.SortFields.Clear
.SortFields.Add Key:=ws.Range("A2:A" & lastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange ws.Range("A1:L" & lastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'合并单元格
.Range("A1:L1").Merge
.Range("A1").Value = "yyy"
'调整列宽
.Columns("B:B").ColumnWidth = 7.5
.Columns("E:E,I:I").ColumnWidth = 3.08
'调整行高和列宽
.Cells.EntireRow.AutoFit
.Columns.AutoFit
'插入空白行
.Rows("1:3").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End With
End Sub
阅读全文