Help with saving file in multiple directories

singcbl

Well-known Member
Joined
Feb 8, 2006
Messages
518
I have presently the codes to save the working file and one with a date stamp. I have been requested to save the same file to another folder in a different directory. I tried recording the macro but the result was not very satisfactory. I appreciate your help to see if I can change the code in SaveFile3. There is an error message if I decide not to save the file after the macro is run.

The filename - "ACR2301B.xls"
The folder location - "I:\Final Cost Forecast-Infra\WP2301\"
The new folder location - "S:\Infrastructure Section\Commercial Management\CR & EW\CR Tracking\ACR Infra"

The existing codes

Code:
 Sub SaveFile()
    Dim f As Variant
    Dim strFileName As String
    Dim strFileDirectory As String
    Dim fname As String
    Dim var As Variant
     
    fname = "ACR-WP2301B"
    strFileName = fname & " " & Format(Now(), "yyyy-mm-dd") & ".xls"
    strFileDirectory = "I:\Final Cost Forecast-Infra\WP2301\"
 
    'Show the SaveAs box
    f = Application.GetSaveAsFilename(InitialFileName:=strFileDirectory & strFileName, _
        FileFilter:="Microsoft Excel Workbook (*.xls),*.xls")
 
    If f <> False Then
        If Dir(strFileDirectory & strFileName, vbNormal) = "" Then
            ActiveWorkbook.SaveAs strFileDirectory & strFileName
        Else
        End If
    End If
        
    Call SaveFile2
    Call SaveFile3

End Sub [code]

[code] Sub SaveFile2()

    Dim strFileName As String
    Dim strFileDirectory As String
    Dim var As Variant
    
    strFileDirectory = "I:\Final Cost Forecast-Infra\WP2301\"
    strFileName = "ACR-WP2301B"
        
    If Dir(strFileDirectory & strFileName & ".xls", vbNormal) = "" Then
        ActiveWorkbook.SaveAs strFileDirectory & strFileName, 56
    Else
        
        var = MsgBox("File " & strFileName & " already exist" & vbNewLine & "Do you want to replace?", vbYesNoCancel)
        If var = vbYes Then
            Application.DisplayAlerts = False
            ActiveWorkbook.SaveAs strFileDirectory & strFileName
            Application.DisplayAlerts = True
        Else
            Exit Sub
        End If
    End If
    
End Sub [code]

[code] Sub SaveFile3()
'
' Macro2 Macro
' Macro recorded 7/23/2010 by andy.tan
'

    ChDir _
        "S:\Infrastructure Section\Commercial Management\CR & EW\CR Tracking\ACR Infra"
    ActiveWorkbook.SaveAs Filename:= _
        "S:\Infrastructure Section\Commercial Management\CR & EW\CR Tracking\ACR Infra\ACR-WP2301B.xls"
End Sub [code]
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Noticed the error in the posting, so have made the correction. Any suggestion?

The existing codes

Code:
 Sub SaveFile()
Dim f As Variant
Dim strFileName As String
Dim strFileDirectory As String
Dim fname As String
Dim var As Variant

fname = "ACR-WP2301B"
strFileName = fname & " " & Format(Now(), "yyyy-mm-dd") & ".xls"
strFileDirectory = "I:\Final Cost Forecast-Infra\WP2301\"

'Show the SaveAs box
f = Application.GetSaveAsFilename(InitialFileName:=strFileDirectory & strFileName, _
FileFilter:="Microsoft Excel Workbook (*.xls),*.xls")

If f <> False Then
If Dir(strFileDirectory & strFileName, vbNormal) = "" Then
ActiveWorkbook.SaveAs strFileDirectory & strFileName
Else
End If
End If

Call SaveFile2
Call SaveFile3

End Sub

Code:
 Sub SaveFile2()

Dim strFileName As String
Dim strFileDirectory As String
Dim var As Variant

strFileDirectory = "I:\Final Cost Forecast-Infra\WP2301\"
strFileName = "ACR-WP2301B"

If Dir(strFileDirectory & strFileName & ".xls", vbNormal) = "" Then
ActiveWorkbook.SaveAs strFileDirectory & strFileName, 56
Else

var = MsgBox("File " & strFileName & " already exist" & vbNewLine & "Do you want to replace?", vbYesNoCancel)
If var = vbYes Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs strFileDirectory & strFileName
Application.DisplayAlerts = True
Else
Exit Sub
End If
End If

End Sub

Code:
 Sub SaveFile3()
'
' Macro2 Macro
' Macro recorded 7/23/2010 by andy.tan
'

ChDir _
"S:\Infrastructure Section\Commercial Management\CR & EW\CR Tracking\ACR Infra"
ActiveWorkbook.SaveAs Filename:= _
"S:\Infrastructure Section\Commercial Management\CR & EW\CR Tracking\ACR Infra\ACR-WP2301B.xls"
End Sub
 
Upvote 0
Hi

I would use the SaveCopyAs method which won't change the name of the Activeworkbook:

Code:
'save current file to different location without changing name of activeworkbook:
 
ActiveWorkbook.SaveCopyAs "G:\SomeFolder\SomeName.xls"
 
ActiveWorkbook.SaveCopyAs "H:\SomeOtherFolder\SomeOtherName.xls"
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top