none
my code is working....almost :( RRS feed

  • Question

  • Hi Colleagues,

    Ca you tell me what is wrong with below code? It does what it's supposed to except naming the pdf file properly.

    Bolded line seems to be the problem. Files are saved but each with the worksheet name instead of what is the the cell D2.

    Thanks in advance for your input...

    Tom

    Sub mak()


            Do Until (Range("A2") = "")

        Sheets("Arkusz1").Range("A2").Copy
        Sheets("Arkusz2").Activate
        Range("D17").Select
        ActiveSheet.Paste
        
        Sheets("Arkusz1").Range("C2").Copy
        Sheets("Arkusz2").Activate
        Range("D14").Select
        ActiveSheet.Paste
        
        Sheets("Arkusz1").Range("E2").Copy
        Sheets("Arkusz2").Activate
        Range("D20").Select
        ActiveSheet.Paste
        
        Sheets("Arkusz1").Range("K2").Copy
        Sheets("Arkusz2").Activate
        Range("D6").Select
        ActiveSheet.Paste
        
        ActiveSheet.ExportAsFixedFormat Filename:=Range("D2").Value, Type:=xlTypePDF
        

        Sheets("Arkusz1").Activate
        
        Rows(2).EntireRow.Delete
        
        Loop
        
    End Sub

    Thursday, March 22, 2018 8:24 PM

All replies

  • I would put Range("D2").Value into a string then debug it and look at what is in the string. Or do something to see what value you are truly getting. You are assuming you know what the value is but you need to confirm the assumption because when things don't work, they aren't working how you expect them to work.


    Sam Hobbs
    SimpleSamples.Info

    Friday, March 23, 2018 12:21 AM
  • Hi spacezaap,

    Does the value of Range("D2") have a correct file path (and file name), like "C:\temp\xxx.pdf"
    Does a specified folder exist?

    Regards,

    Ashidacchi >> http://hokusosha.com/

    Friday, March 23, 2018 5:00 AM