View Full Version : VBA code for saving csv file to certain path
Michael 1962
03-08-2012, 10:37 AM
I need code to save a file with the following attributes. This path is on a network.
Name file string found in cell F1
Save file as .csv file
Save file to this path: H:\Private\Distribution\Small Package List\CSV
This file originates as an xlsm.
TMShucks
03-09-2012, 03:05 AM
Maybe:
ChDir "H:\Private\Distribution\Small Package List\CSV"
ActiveWorkbook.SaveAs _
Filename:= "H:\Private\Distribution\Small Package List\CSV\Sample Test.csv", _
FileFormat:=xlCSV, _
CreateBackup:=False
Regards, TMS
mancubus
03-09-2012, 03:47 AM
Sub file_SaveAs()
Dim wb As Workbook, ws As Worksheet
Dim fPath As String, fName As String
Set wb = ThisWorkbook 'refers to workbook that contains this macro
'or
'Set wb = ActiveWorkbook 'refers to workbook which is currently active
'or
'Set wb = Workbooks("MyBook.xlsm")
Set ws = wb.Worksheets("Sheet1") 'change to suit
'or
'Set ws = wb.ActiveSheet
fPath = "H:\Private\Distribution\Small Package List\CSV"
If Right(fPath, 1) <> "\" Then fPath = fPath & "\"
fName = ws.Range("F1").Value
wb.SaveAs Filename:=fPath & fName, FileFormat:=xlCSV
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.