View Single Post
 
Old 08-20-2017, 06:23 AM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Perhaps this...
Code:
Sub SaveInvWithNewName()

    Dim NewFN
    Dim variable1
    Dim variable2

With ActiveSheet    '<~~ this is the original invoice

    ' are these cells filled in?
    If .Range("F16") = "" Or .Range("E31") = "" Or .Range("G31") = "" Then
        MsgBox "some stuff missing"
        Exit Sub
    End If
    
    variable1 = .Range("A32").Value
    variable2 = .Range("A35").Value
    .Copy   'creates new active workbook containing this invoice
End With

With ActiveSheet    '<~~ now dealing with sheet in newly created workbook
    .Range("A32").Value = variable1
    .Range("A35").Value = variable2
    .Cells.Locked = True
    .Protect
    NewFN = "C:\invoice\" & .Range("I5").Value & .Range("H5").Value & .Range("I49").Value & .Range("F16").Value
End With

With ActiveWorkbook
    .SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook    '<~~ this will add the file extention .xlsx
    Application.DisplayAlerts = True
    .PrintOut From:=1, To:=1, copies:=2
    .Close SaveChanges:=False
End With
    
    Call NextInvoice

End Sub
Reply With Quote