|
想要保留原格式,请再试一试
- Sub 导出工作表选定区域()
- On Error Resume Next
- Dim sRng As Range, sh, i, nm '定义区域为选择区域
- 'Set sRng = Selection
- Dim tBook As Workbook
- Dim fName$ '定义工作薄完整名
- sh = InputBox("请输入要导出的工作表的名字") '输入要导出工作表的名称
- Sheets(sh).Visible = True
- Sheets(sh).Select
- Set sRng = Application.InputBox("请选择数据输出范围", Type:=8) '这个语句是选择区域。
- Set tBook = Workbooks.Add '新建工作薄
- fName = ThisWorkbook.Path & "" & sh & Format(Date, "yyyy-MM-dd") & "_" & ".xlsx" '& Format(Time, "hhmmss")日期_时间.xlsx
-
- '将选择的区域复制到新工作簿
- sRng.Copy
- tBook.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone
- Application.CutCopyMode = False '清除剪切板内容
-
- With tBook
- .SaveAs fName, xlOpenXMLWorkbook '将新工作簿另存为指定路径和文件名
- .Close False '关闭新工作簿
- End With
-
- Shell "explorer.exe /select," & fName, vbNormalFocus '在浏览器中选中导出工作薄
- Set tBook = Nothing
- End Sub
复制代码 |
|