So, I read a lot of topics and similar questions, but could not understand properly.
I am running the code below, both the destinfilename
and SourceFileName
are correct, I checked with Debug.Print
.
Debug gave me these results:
SourceFileName = "C:\Users\Renan\Desktop\BulkPdf\Documentos gerados\Doc.1-aaaaa.pdf"
namefile2 = "Doc.1-aaaaa.pdf"
destinfilename = "C:\Users\Renan\Desktop\BulkPdf\Documentos gerados\Doc.1-aaaaa"
When I copy the directory, and the destinfilename
and copy on IE, work just perfect, but when running the code, always got "Error 53 File Not Found"
I tried putting and removing "", nothing worked.
NOTE 1: I want to move the file Doc.1-aaaaa.pdf
to a folder with the same name, so the folder name is Doc.1-aaaaa
NOTE 2: I've been asking a lot of questions, I know and apologize, but I don't have a background on programming - I'm a lawyer - but I'm trying to learn something new by myself (without classes, just YouTube and forum) and VBA is really fun and useful.
I'm using this code. The problem is in the code?
Sub creating_pdfs()
Call LoopThroughFilesInFolder("C:\Users\Renan\Desktop\BulkPdf\Documentos gerados\", "Doc*")
End Sub
Sub LoopThroughFilesInFolder(strDir As String, Optional strType As String)
Dim FSO As Object
Dim SourceFileName As String, destinfilename As String
Dim namefile1 As String
Dim dot
Dim namefile2 As String
Dim file As Variant
If Right(strDir, 1) <> "\" Then strDir = strDir & "\"
file = Dir(strDir & strType)
While (file <> "")
Debug.Print file
SourceFileName = "C:\Users\Renan\Desktop\BulkPdf\Documentos gerados\" & file
namefile1 = file
dot = InStr(namefile1, "pdf") - 2
namefile2 = Left(namefile1, dot)
destinfilename = "C:\Users\Renan\Desktop\BulkPdf\Documentos gerados" & "\" & namefile2
Debug.Print namefile2
Debug.Print SourceFileName
Debug.Print destinfilename
Set FSO = CreateObject("scripting.FileSystemObject")
FSO.MoveFile Source = SourceFileName, Destination:=destinfilename
file = Dir
Wend
End Sub