Hello all VB Members,

I made a script,
when I have opened a .doc file and run the script.
the script can see the active location, copy all .pdf files from the active path, navigates one level up creates a folder called translation to.
my problem is..
if the folder "translation to" already exists I get an error.

can someone help me to modify my code
I want my script work this way.

if the folder already exists overwrite the folder,
also if the folder contains files keep the files but overwrite the folder.


see Code


Sub Demo()
Dim StrOldPath As String, StrNewPath As String
StrOldPath = ActiveDocument.Path
StrNewPath = Left(StrOldPath, InStrRev(StrOldPath, "\"))
StrOldPath = StrOldPath & "\"


nf = "translation to"
nf = StrNewPath & nf
MsgBox (nf)
MkDir nf


FileExt = "*.pdf*" '<< Change
'You can use *.* for all files or *.doc for Word files

If Right(StrOldPath, 1) <> "\" Then
StrOldPath = StrOldPath & "\"
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(StrOldPath) = False Then
MsgBox StrOldPath & " doesn't exist"
Exit Sub
End If

If FSO.FolderExists(nf) = True Then
MsgBox ToPath & " doesn't exist"
Exit Sub
End If

FSO.CopyFile Source:=StrOldPath & FileExt, Destination:=nf



End Sub