I have VBA code to open a new workbook here is my problem:
I want open a new workbook(2) and save it with a date to be pasted in B1.
I want to then activate workbook(1) and copy selected cells and paste them into workbook2.
Then save workbook2 with the following title (SF_GR110_MMDD)
What I am trying to accomplish is not overwriting this file every time it is created.
Here is the code I have already:
'2. Creates the csv file for Oracle and sends it to the Livestock\Files folder on your c drive.
Application.DisplayAlerts = False
Set NewBook = Workbooks.Add
With NewBook
.SaveAs filename:= _
"C:\livestock\files\" & Format("SF_GR110") & "_" & ".csv", FileFormat _
:=xlTextPrinter, CreateBackup:=False
End With
Application.DisplayAlerts = True
Workbooks("SD Grain.xlsm").Activate
Sheets("CSV").Activate
Worksheets("CSV").Range("B11:B14").Copy
Workbooks("SF_GR110_.csv").Activate
ActiveSheet.Range("a1").PasteSpecial _
Paste:=xlPasteValuesAndNumberFormats
Selection.Columns.AutoFit
ActiveWindow.DisplayZeros = False
Range("A1").Select
Application.CutCopyMode = False
Workbooks("SF_GR110_.csv").Close SaveChanges:=True
Workbooks("SD Grain.xlsm").Activate
Application.CutCopyMode = False
Thanks for any help.
I have been trying this code in the file name but it gives me a Syntax error
- plus I can't figure out how to make the file save revert back to the date:
"C:\livestock\files\" & Format("SF_GR110") & "_" & (Sheet1.Range("B1"), "mmdd") & ".csv", FileFormat _
Here is what I did:
Set newbook = Workbooks.Add
Workbooks("SD Grain.xlsm").Activate
Sheets("CSV").Activate
Worksheets("CSV").Range("B11:B14").Copy
newbook.Activate
ActiveSheet.Range("a1").PasteSpecial _
Paste:=xlPasteValuesAndNumberFormats
Selection.Columns.AutoFit
ActiveWindow.DisplayZeros = False
Range("A1").Select
Application.CutCopyMode = False
With newbook
.SaveAs filename:="C:\livestock\files\SF_GR110_" & Format(Sheet1.Range("H3"), "mmdd") & ".csv" _
, FileFormat:=xlTextPrinter, CreateBackup:=False
.Close savechanges:=True
End With
Workbooks("SD Grain.xlsm").Activate
Application.CutCopyMode = False
Bookmarks