crystalneedshelpplzthnx
Board Regular
- Joined
- Nov 24, 2017
- Messages
- 55
- Office Version
- 365
- Platform
- Windows
Good Day,
I would like some help on appending a duplicate file name during a looped save.
Name
Name (2)
This is my current code:
I have tried other codes found online but I keep getting an Invalid procedure call or argument (Error 5) on the below code:
Thank you
Crystal
I would like some help on appending a duplicate file name during a looped save.
Name
Name (2)
This is my current code:
Code:
Sub WM_Save_File()
Dim Path As String
Dim fileName As String
'Move Original File Name
Range("d1").Select
Selection.Cut
Range("A1").Select
ActiveSheet.Paste
'FIRST CELL
Dim sht As Worksheet, csheet As Worksheet
Set csheet = ActiveSheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible Then
sht.Activate
Range("A1").Select
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 1
End If
Next sht
csheet.Activate
If Range("z1") = "TimeStamp" Then
'SAVE AS
Path = "C:\Users\CRAGIN\Downloads\Reports w time code\"
fileName = Range("B1")
ActiveWorkbook.SaveAs fileName:=Path & fileName & ".xls", FileFormat:=xlNormal
Range("z1").Select
Selection.ClearContents
Else
'SAVE AS
'I would like this portion to append when a duplicate file path has been found
Path = "C:\Users\CRAGIN\Downloads\Reports\"
fileName = Range("B1")
ActiveWorkbook.SaveAs fileName:=Path & fileName & ".xls", FileFormat:=xlNormal
End If
End Sub
I have tried other codes found online but I keep getting an Invalid procedure call or argument (Error 5) on the below code:
Code:
Sub WM_LoopThroughFiles()'Open and Format all WM reports (Download folder)
'bEgIn
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
'Folder where raw data files are stored
FolderName = "C:\Users\CRAGIN\Downloads\Raw Data Files\"
If Right(FolderName, 1) <> Application.PathSeparator Then FolderName = FolderName & Application.PathSeparator
Fname = Dir(FolderName & "*.xls")
'loop through these files
Do While Len(Fname)
With Workbooks.Open(FolderName & Fname)
'Save original file name in cell d1
Range("D1").Select
ActiveCell.FormulaR1C1 = _
"=LEFT(MID(CELL(""filename""),FIND(""kk"",CELL(""filename"")),LEN(CELL(""filename""))+1-FIND(""kk"",CELL(""filename""))),FIND("".xls"",MID(CELL(""filename""),FIND(""kk"",CELL(""filename"")),LEN(CELL(""filename""))+1-FIND(""kk"",CELL(""filename""))))-1)"
'=LEFT(MID(CELL("filename"),FIND("kk",CELL("filename")),LEN(CELL("filename"))+1-FIND("kk",CELL("filename"))),FIND(".xls",MID(CELL("filename"),FIND("kk",CELL("filename")),LEN(CELL("filename"))+1-FIND("kk",CELL("filename"))))-1)
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
'SAVE Raw data file AS Test
Dim Path As String
Dim fileName As String
Path = "C:\Users\CRAGIN\Downloads\"
fileName = "Test"
ActiveWorkbook.SaveAs fileName:=Path & fileName & ".xls", FileFormat:=xlNormal
'applicationRun
Application.Run "WM_Formats"
End With
' go to the next file in the folder
Fname = Dir 'THIS IS WHERE I GET THE ERROR
Loop
'Delete Test file
Kill "C:\Users\CRAGIN\Downloads\Test.xls"
'Application.Run "WM_LoopThroughFiles_FileName"
'eNd
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Thank you
Crystal