【发布时间】:2021-01-12 19:38:17
【问题描述】:
之前我问了一个关于如何使用 XLDialogaveAs 将 Excel 文件保存到指定位置的问题(适用于尚未保存的文件)-Excel VBA XLDialogSaveAs function not working。但是,我正在尝试对已保存在计算机中的 Excel 文件执行相同的操作,但改为更改位置。
我有以下代码:
Option Explicit
Sub externalRatingChangeFile()
'Declare the data type of the variables
Dim wks As Worksheet
Dim sFilename As String
'Set wks to the current active worksheet
Set wks = ActiveWorkbook.ActiveSheet
'Set the location to save the file to a variable
sFilename = "H:\testing file"
'Save as .xlsx file in the specific location stated earlier
'If there are errors in the code, set wks to nothing and end the process
On Error GoTo err_handler
ChDrive sFilename
ChDir sFilename
Application.Dialogs(xlDialogSaveAs).Show (sFilename & "\TestingFile - " & Format(Date, "YYYYMMDD") & ".xlsx")
'System to/not display alerts to notify Users that they are replacing an existing file.
Application.DisplayAlerts = True
err_handler:
'Set Wks to its default value
Set wks = Nothing
End Sub
有谁知道我可以使用哪个excel VBA函数来更改Excel文件的保存位置,并在保存前在对话框中显示指定位置?谢谢!
【问题讨论】:
-
See SaveAs 不会接受包含“.”的字符串在 Excel VBA[](stackoverflow.com/questions/36320580/…) 中。
-
谢谢! @吉普车