2 thoughts on “Debug Excel VBA Code Line by Line for Errors

  1. Sir,
    I found the video very useful and informative. I followed along as you walked through the entire process with the Debug.

    I could not detect any error or misplaced variable. What I am noticing is that Ln27 IS NOT the end product file of Ln 25. It looks like it is copying/renaming the first PDF file into the second PDF; which is incorrect.

    Sub NextInvoice()
    ‘H10 is the invoice number
    ‘H12 in the customer ID
    Application.DisplayAlerts = False
    Range(“H10”).Value = Range(“H10”).Value + 1
    Range(“A16:I35”).ClearContents
    Range(“D37”).NumberFormat = (“dd mmm yyyy”)
    End Sub
    Sub SaveInvWithNewName()
    Application.DisplayAlerts = False
    Dim DC_date As Date
    Dim myFile As String, lastRow As Long
    Dim myFile1 As String, lastRow1 As Long
    ‘Copy Invoice to a new workbook
    ‘Create [Proforma Invoice]PFI*.xlsx
    ‘Create [Proforma Invoice]PFI*.PDF
    ‘Create [Receipt]RE00*.xlsx
    ‘Create [Receipt]RE00*.PDF

    ActiveSheet.Copy
    NewFN = “T:InvoicesCustomer InvoicesTB 918273” & Range(“H12”) & “_PFI00” & Range(“H10”).Value & “.xlsx”
    ActiveSheet.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
    myFile = “T:InvoicesCustomer InvoicesTB 918273” & Range(“H12”) & “_PFI00” & Range(“H10”).Value & “.pdf”
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFile
    NewFeNe = “T:InvoicesCustomer InvoicesTB 918273” & Range(“H12”) & “_RE00” & Range(“H10”).Value & “.xlsx”
    ActiveSheet.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
    myFile = “T:InvoicesCustomer InvoicesTB 918273” & Range(“H12”) & “_RE00” & Range(“H10”).Value & “.pdf”
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFile
    value_1 = Sheets(“OrderSheet”).Range(“B41”)
    value_2 = Sheets(“OrderSheet”).Range(“D41”)
    value_3 = Sheets(“OrderSheet”).Range(“F41”)

    ActiveSheet.Range(“A7”) = value_1
    ActiveSheet.Range(“A37”) = value_2
    ActiveSheet.Range(“D37”) = value_3
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    NextInvoice
    End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.