|
楼主 |
发表于 2017-12-29 19:21
|
显示全部楼层
Private Sub CommandButton5_Click() '导出
On Error Resume Next '
Dim x As Long
Dim t
x = Range("a65536").End(xlUp).Row
Dim bname As String
Dim cname As String
bname = Range("b5") '客户名称
cname = Range("g4") '订单编号
Range("A1:h" & x).Select
Range("h" & x).Activate
t = MsgBox("按 是 将工作表导出为.PDF格式,按 否 将工作表导出为.htm网页格式,导出文件保存在同文件目录下。", vbYesNo, "工作表导出")
If t = vbYes Then
'输出为.PDF
Range("A1:h" & x).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ActiveWorkbook.Path & "\" & bname & "-出货清单-" & cname & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
Else
'导出为.htm网页
With ActiveWorkbook.PublishObjects.Add(xlSourceSheet, _
ActiveWorkbook.Path & "\" & bname & "-出货清单-" & cname & ".htm", "发货单" _
, "", xlHtmlStatic, "Luo_0412", "")
.Publish (True)
.AutoRepublish = False
End With
'指定单元格区域:
'With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
' ActiveWorkbook.Path & "\出货清单-" & cname & ".htm", ActiveSheet.Name, "$A$1:$J$21", xlHtmlStatic, "Luo_0418", _
' ActiveSheet.Name & " ")
' .Publish True
' .AutoRepublish = False
' End With
End If
End Sub
自己根据需要修改这三处就行了
bname = Range("b5") '客户名称
cname = Range("g4") '订单编号
输出文件名称:
bname & "-出货清单-" & cname & ".pdf"
bname & "-出货清单-" & cname & ".htm" |
|