VBA Save Copy As to specific folder

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, Is it possible to Save a copy of an active workbook to a specific folder as a CSV format file while using the dialog pop up? Also I have an issue where If I cancel then the active book name changes to False, can someone help please

Here is what I have at the moment which changes the active book name
Code:
Option Explicit
Dim varResult As Variant
Const StrPath As String = "C\User\Documents\"
Sub sbSaveExcelDialog()
    varResult = Application.GetSaveAsFilename(FileFilter:="CSV Files (*.csv), *.csv", Title:="Save As CSV", InitialFileName:=StrPath)
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi deca,
I think to do this you need an other book to run the macro, so you can get back to your .xlsx file
Cheers
Sergio
 
Upvote 0
I don't require the .xlsx file, The end user needs to save a copy of the workbook that they are using as a CSV file in a specific folder, I chose to use the dialog popup so they can save the filename as a specific name for each workbook they save.
 
Upvote 0
Try this:
Code:
Public Sub Save_Workbook_Copy_As_CSV()

    Dim folderPath As String
    Dim csvFile As String
    
    folderPath = "C:\Users\username\Documents"
 
    csvFile = Application.GetSaveAsFilename(InitialFileName:=folderPath, _
                FileFilter:="CSV Files (*.csv), *.csv", Title:="Save As CSV")
 
    If csvFile <> "" And csvFile <> "False" Then
        Application.ScreenUpdating = False
        ActiveSheet.Copy
        On Error Resume Next
        ActiveWorkbook.SaveAs fileName:=csvFile, FileFormat:=xlCSV, _
            Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False, ConflictResolution:=xlUserResolution
        On Error GoTo 0
        'Close .csv workbook, leaving original workbook open
        ActiveWorkbook.Close SaveChanges:=False
        Application.ScreenUpdating = True
    End If

End Sub
 
Upvote 0
Brilliant, works perfectly, Thanks for your help
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,706
Members
449,118
Latest member
MichealRed

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