- [返回列表] [ 发布:2022/11/28 10:10:04 ] [ 浏览: ] [ 字体:大 | 小 ]
- 通用Excel填报的时候,怎么实现点击按钮,把当前报表导出为Excel文件
通用Excel填报的时候,怎么实现点击按钮,把当前报表导出为Excel文件,效果等同于“另存为”
如下图,点击一个自定义按钮,并加入简单VBA代码,即可实现:
VBA代码如下:
Sub 导出Excel()
Dim obj As Object
Dim book As Workbook
Dim loc As Variant
Set obj = Application.COMAddIns.Item("prjAddin.Office_Addin").Object
Application.DisplayAlerts = False
Sheets("Sheet1").Activate
ActiveWorkbook.Worksheets("sheet1").Copy
loc = Application.GetSaveAsFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="另存为", InitialFileName:=Range("C3"))
If loc <> False Then
Set book = ActiveWorkbook
ActiveWorkbook.SaveAs Filename:=loc, FileFormat:=51
obj.SaveReport
MsgBox "导出Excel成功 ", 64, "互和科技"
book.Close True
Exit Sub
End If
Application.DisplayAlerts = True
Set obj = Nothing
End Sub
直接复制上述代码,在通用Excel模板上新建一个按钮,然后指定宏即可。