|
本帖最后由 a33030626 于 2018-6-7 08:29 编辑
VSTO中怎么复制某一特定工作表到新工作簿并另存, 哪位大神写一个范例谢谢
VBA 代码如下
Sub 复制报表()
Dim Sh As Integer
Dim Th As Workbook, Wb As Workbook
Dim il As String
Set Th = ThisWorkbook
il = Left(Th.Name, InStr(Th.Name, ".") - 1) & "-01" & ".xlsx" '要另存的工作表名
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Sh = 1 To Sheets.Count
If Sheets(Sh).Visible = True And Right(Sheets(Sh).Name, 3) = "报表1" Then '当工作表可见和右边3个字等于报表1
Th.Sheets(Sh).Copy before:=Sheets(1) '复制到sheet1前面
Cells.Copy
Cells.PasteSpecial Paste:=xlPasteValues '粘贴成值
Columns("L:R").Delete '删除L:R列
ActiveSheet.Move '移动到新工作簿
Set Wb = Workbooks(Workbooks.Count)
End If
Next Sh
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Wb.SaveAs Th.Path & "\" & il, FileFormat:=xlWorkbookDefault
End Sub
|
|