Excel VBA 将 Sheet 作为 Excel 文件保存到路径并覆盖文件
Excel VBA Saving Sheet to Path as Excel File and Overwriting File
我在使用一些非常基本的东西时遇到了一些麻烦。知道这里出了什么问题吗?
Sub Test()
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Master List").SaveAs "C:\Test\ART.xlsx", 52
Application.DisplayAlerts = True
End Sub
导出工作表
Option Explicit
Sub exportSheet()
Const FolderPath As String = "C:\Test\"
Const FileName As String = "ART.xlsx"
Const SheetName As String = "Master List"
On Error Resume Next
Workbooks(FileName).Close
On Error GoTo 0
With ThisWorkbook
Application.ScreenUpdating = False
.Sheets(SheetName).Copy
With ActiveWorkbook
Application.DisplayAlerts = False
.SaveAs FolderPath & FileName, xlOpenXMLWorkbook ' 51 (.xlsx)
Application.DisplayAlerts = True
.Close False
End With
' Open Folder Path in Windows File Explorer.
'.FollowHyperlink FolderPath
'.Close
Application.ScreenUpdating = True
End With
End Sub
我在使用一些非常基本的东西时遇到了一些麻烦。知道这里出了什么问题吗?
Sub Test()
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Master List").SaveAs "C:\Test\ART.xlsx", 52
Application.DisplayAlerts = True
End Sub
导出工作表
Option Explicit
Sub exportSheet()
Const FolderPath As String = "C:\Test\"
Const FileName As String = "ART.xlsx"
Const SheetName As String = "Master List"
On Error Resume Next
Workbooks(FileName).Close
On Error GoTo 0
With ThisWorkbook
Application.ScreenUpdating = False
.Sheets(SheetName).Copy
With ActiveWorkbook
Application.DisplayAlerts = False
.SaveAs FolderPath & FileName, xlOpenXMLWorkbook ' 51 (.xlsx)
Application.DisplayAlerts = True
.Close False
End With
' Open Folder Path in Windows File Explorer.
'.FollowHyperlink FolderPath
'.Close
Application.ScreenUpdating = True
End With
End Sub