Hey everybody, I have a quick question regarding file operations and moving/renaming them in particular.
Here's my code:
It kind of works in that it renames it, checks to see if the file exists, if it does, increments it, if it doesn't, moves it, and links it properly in the sheet. The issue is that it seemingly competely ignores that whole "Files = FileAddress & ".pdf"" line. The files in the destination folder are of no type and cannot be opened without manually adjusting the file extension - which is what I thought I was doing in the code.
What am I doing wrong?
Here's my code:
Code:
FileAddress = "X:\Database\MTR's\PDF Folder\" + EditMTR.HeatNumber
If PONumber.Value <> "" Then FileAddress = FileAddress + "-" + PONumber.Value
Set FSO = CreateObject("Scripting.FileSystemObject")
Count = 0
Do While FSO.FileExists(FileAddress) = True
Count = Count + 1
FileAddress = FileAddress + "(" & Count & ")"
Loop
Name Files As FileAddress
Files = FileAddress & ".pdf"
If ActiveSheet.Name = "MTRs" Then Location = ActiveCell.Row Else: Location = Sheets("Search").Cells(ActiveCell.Row, 20).Value
Sheets("MTRs").Hyperlinks.Add Anchor:=Cells(Location, 1), Address:=Files
If ActiveSheet.Name = "Search" Then ActiveSheet.Hyperlinks.Add Anchor:=Cells(ActiveCell.Row, 1), Address:=Files
It kind of works in that it renames it, checks to see if the file exists, if it does, increments it, if it doesn't, moves it, and links it properly in the sheet. The issue is that it seemingly competely ignores that whole "Files = FileAddress & ".pdf"" line. The files in the destination folder are of no type and cannot be opened without manually adjusting the file extension - which is what I thought I was doing in the code.
What am I doing wrong?