previously I asked a question on how to save an Excel file to an designated location using XLDialogaveAs (which works for files that have yet to be saved) - Excel VBA XLDialogSaveAs function not working. However, I am trying to do the same thing for an Excel file that have already been saved in the computer, but change the location instead.
I have the following codes below:
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
Does anyone know which excel VBA function can I use to change the saving location of the Excel file, and show the designated location in the dialog box before saving? Thanks!