Consulting

Results 1 to 7 of 7

Thread: Copy PDF

  1. #1

    Copy PDF

    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
    Attached Files Attached Files
    Last edited by dodonohoe; 01-28-2014 at 06:27 AM. Reason: Added a file

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    attach please a sample file

  3. #3
    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

  4. #4
    try
    FileCopy path1 & " \ " & MyFile, NewFilepath


  5. #5
    Quote Originally Posted by westconn1 View Post
    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

  6. #6
    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

  7. #7
    There is a space
    i can see that in your post above, but i could not pick that in your posted code
    anyway, good it is fixed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •