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
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