User to choose path and file nane to save a csv file

bssimmonds

New Member
Joined
Apr 5, 2016
Messages
2
I would like for the user to be able to choose the path and filename to save a file.
I can embed the path and filename in the VBA code but I would like normal Excel save screen to be displayed.
can anyone help please?

Thanks, Bernie

This is my code with embedded path

Sub ExportToFile()
' This routine copies the "Exported" data
' creates a new Workbook
' pastes the exportdata
' saves the workbook to the current path with file name in variable "newname"

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim oldname$, oldpath$, oldformat, newname$

'get current path and filename
With ActiveWorkbook
oldpath = .Path
oldname = .Name
End With

'set file name
'newname = "Export " + oldname
'MsgBox (oldpath + "\" + newname)

'Remove the last 5 characters of the filename to remove the extention
oldname = Left(oldname, Len(oldname) - 5)

'Get Filename to save file
newname = InputBox("Enter desired filename or click OK to accept default", _
"Enter Filename", "Export " + oldname)

'make sure the filename ends with .csv
If Not Right(newname, 4) = ".csv" Then newname = newname + ".csv"

'Copy export data
Sheets("EXPORT").Activate
Range("A1:A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy

'Create new workbook and paste exportdata
Workbooks.Add Template:="Workbook"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

'Save Exportfile and csv then close file
ActiveWorkbook.SaveAs Filename:=oldpath + "\" + newname, FileFormat:=xlCSV, CreateBackup:=False
ActiveWindow.Close False

'goto Processing sheet
Sheets("PROCESSING").Activate
Range("A1").Select
Application.DisplayAlerts = True
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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