Good Morning,
I'm currently using two different codes, but I would like to blend these two together...
One code, simply saves the entire workbook as a spreadsheet, which is saving the file under the name which is referenced to a specific cell.
the file is automatically saved to a pre determined location within the code.
this code is currently working the way I need it to.
I have another code, which saves my selection as a .CSV file, however It pops up the windows save box, which I have to manually locate the file where I want to save it to, and also name the file manually....
Essentially, what I would like to do.
is have it where the 2nd code, will Save my selection as a CSV file, and automatically name its self based on whats in a specific cell, and saved to a specific location.
I'm currently using two different codes, but I would like to blend these two together...
One code, simply saves the entire workbook as a spreadsheet, which is saving the file under the name which is referenced to a specific cell.
the file is automatically saved to a pre determined location within the code.
this code is currently working the way I need it to.
Code:
Sub SaveFileAsDate()
Dim WSName As String, CName As String, Directory As String, savename As String
''''''''''''''''''''CHANGE THE NEXT 3 LINES TO FIT YOUR NEEDS'''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WSName = "Sheet1"
'change "Sheet1" to sheet tab name containing cell reference
CName = "C2"
'change "A1" to the cell with your date
Directory = "Z:\Accounting\Accounts Receivable\Endeavor ADP\1-Grids By First Name\"
'directory you want to save to--(make sure string ends with forward slash \)
'...to save to default directory change to "" (Null)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
savename = Sheets(WSName).Range(CName).Text
If Directory = "" Then Directory = CurDir & "\"
On Error GoTo errorsub:
ActiveWorkbook.SaveAs Filename:=Directory & savename & ".xls"
Exit Sub
errorsub:
Beep
MsgBox "Changes not saved!", vbExclamation, Title:=savename & ".xls"
End Sub
I have another code, which saves my selection as a .CSV file, however It pops up the windows save box, which I have to manually locate the file where I want to save it to, and also name the file manually....
Code:
[Sub CSVFile()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As Variant
FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")
ListSep = Application.International(xlListSeparator)
If Selection.Cells.Count > 1 Then
Set SrcRg = Selection
Else
Set SrcRg = ActiveSheet.UsedRange
End If
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrTextStr = ìî
For Each CurrCell In CurrRow.Cells
If IsNumeric(CurrCell.Value) Then
CurrTextStr = CurrTextStr & CurrCell.Value & ListSep
Else
CurrTextStr = CurrTextStr & "" & CurrCell.Value & "" & ListSep
End If
Next
While Right(CurrTextStr, 1) = ListSep
CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) - 1)
Wend
Print #1, CurrTextStr
Next
Close #1
End Sub
Essentially, what I would like to do.
is have it where the 2nd code, will Save my selection as a CSV file, and automatically name its self based on whats in a specific cell, and saved to a specific location.