PDA

View Full Version : [SOLVED] Copy PDF



dodonohoe
01-28-2014, 04:10 AM
Hi all,

I succeded in opening and printing a pdf file using VBA. I am trying to copy a pdf file from one location to another using variables but I am getting a error Type Mismatch. I have highlighted in my code (at the bottom) where the error is occuring.

Thanks


Sub CopyPDF()

'This sub is for the PDF piece



Dim w As Workbook
Set w = ActiveWorkbook



Dim fileformat As String
Dim path1 As String
Dim Variablez As String
Dim path2 As String
Dim FileName As String
Dim Action As String
Dim MyFile As String
Dim wb As Workbook
Dim Location As String
Dim strPathNFile As String
Dim NewFile As String


fileformat = "pdf"
path1 = Trim(Cells(6, 3))
Variablez = Trim(Cells(6, 4))
path2 = Trim(Cells(6, 5))
FileName = Trim(Cells(6, 6))
Action = Trim(Cells(6, 7))

Location = Trim(Cells(6, 9))
NewFile = Trim(Cells(6, 10))



'Gives the full file name
MyFile = Dir(path1 & "\" & Variablez & "\" & path2 & "\" & FileName & "." & fileformat)

'Gives the file path excluding the file name


If Variablez = "" Or path2 = "" Then

FilePath = path1

Else

FilePath = path1 & "\" & Variablez & "\" & path2

End If

MyNewFile = Dir(Location & "\" & NewFile)

NewFilepath = Location & "\" & NewFile



'call the copy piece

If MyFile <> "" And FileName <> "" And Action = "Copy" Then

Cells(x, 8) = "This report has been copied"


'FileCopy "C:\TestFile.pdf", "C:\Grails\DesTestFile.pdf"

'RUN TYPE ERROR 13 TYPE MISMATCH BEING THROWN ON THE NEXT LINE

FileCopy "path1 & " \ " & MyFile", "NewFilepath"


End If


End Sub

patel
01-28-2014, 05:23 AM
attach please a sample file

dodonohoe
01-28-2014, 06:29 AM
Hi Patel,

I have added the worksheet where all the variables are listed. I have not attached the PDF as it contains sensitive info but it is just a regular pdf. I can add a blank pdf called Acca Renewal (as per the variable name in the worksheet if you require?

Thanks,

Des

westconn1
01-29-2014, 03:17 AM
try

FileCopy path1 & " \ " & MyFile, NewFilepath

dodonohoe
01-29-2014, 03:43 AM
try

FileCopy path1 & " \ " & MyFile, NewFilepath





Hi Westconn1,

I tried that and it gives me an error that the filepath can not be found. When I hover over the variables they seem correct.

FileCopy path1 & " \ " & MyFile, NewFilepath reads as follows

C:\Source & "\" & Acca Renewal.PDF, C:\Destination\Des Test.PDF

So just to be clear, I am trying to copy Acca Renewal.pdf from C:\Source to C:\Destination and renaming the file as Des Test.PDF

Thanks,

Des

dodonohoe
01-29-2014, 04:20 AM
Hi westconn1,

There is a space FileCopy path1 & " \ " & MyFile, NewFilepath before and after the | which shouldn't be there. Works like a treat now. So just to clarify

FileCopy path1 & " \ " & MyFile, NewFilepath should be FileCopy path1 & "\" & MyFile, NewFilepath

Thanks for the help I am marking this as solved.

Des

westconn1
01-29-2014, 01:18 PM
There is a spacei can see that in your post above, but i could not pick that in your posted code
anyway, good it is fixed