PDA

View Full Version : [SOLVED:] File copy wont copy to the right folder.



afgg
06-08-2016, 03:10 PM
I have a folder called 'productions' inside a folder, but when I click on the button to copy .pdf from the source, the files don't get copied inside the productions folder, instead it gets copied to the Parent folder.

in other words, the code works until the comboBox3, but fails to move one step forward and copy the pdf's inside the productions folder.


Private Sub CommandButton8_Click() ' PDF buttons

On Error GoTo er:
Dim FSO As Object
Set FSO = CreateObject("scripting.filesystemobject")
FSO.CopyFile "C:\Users\XXXX\Desktop\Changes\*.PDF", "S:\PDF_Jobs\" & ComboBox1 & "\" & ComboBox2 & "\" & ComboBox3 & "\" & Productions, False
MsgBox "Files Copied"
Exit Sub
er: MsgBox "Files already exists"
End Sub

thanks

offthelip
06-08-2016, 03:40 PM
It may seem very basic but have you tried:

FSO.CopyFile "C:\Users\XXXX\Desktop\Changes\*.PDF", "S:\PDF_Jobs\" & ComboBox1 & "\" & ComboBox2 & "\" & ComboBox3 & "\Productions", False

Paul_Hossler
06-08-2016, 05:25 PM
Do Combobox 1,2,3 values have spaces in them?

afgg
06-09-2016, 07:08 AM
It may seem very basic but have you tried:

FSO.CopyFile "C:\Users\XXXX\Desktop\Changes\*.PDF", "S:\PDF_Jobs\" & ComboBox1 & "\" & ComboBox2 & "\" & ComboBox3 & "\Productions", False


Thanks!! it worked! It is weird though, I don't understand why it would act up like that!

Paul_Hossler
06-09-2016, 06:44 PM
In this, Productions is assumed to be a variable (not defined, so the error kicks in)


"\" & Productions,


In this, Productions is part of the literal folder name string


"\Productions",

(offthelip -- Good catch )

gmayor
06-10-2016, 12:28 AM
You might also consider

fso.CopyFile Environ("USERPROFILE") & "\Desktop\Changes\*.PDF", "S:\PDF_Jobs\" & ComboBox1 & "\" & ComboBox2 & "\" & ComboBox3 & "\Productions", False
which will make the code transferrable (provided the desktop sub folder exists)

snb
06-10-2016, 01:59 AM
Or even the internationally more robust:


Sub M_snb()
CreateObject("scripting.filesystemobject").copyfile CreateObject("wscript.shell").specialfolders(10) & "\Changes\*.PDF", Join(Array("S:", "PDFJobs", combobox1, combobox2, combobox3, "Productions"), "\")
End Sub


NB. not every language uses the word 'desktop' for the desktop