Sub CreateInvoice()
Dim rng As Range
Set rng = Application.InputBox("Click which customer to generate an Invoice for:", "Athena Global Advisors, Inc", Type:=8)
Dim answer As Integer
Application.DisplayAlerts = False
'insert an apostrophe in front of the code below or delete it IF you do not wish to hide it
'Sheets("Template").Visible = True
If rng <> "" Then
Sheets("Template").Copy After:=Sheets("Invoices and Bills Template")
On Error Resume Next
ActiveSheet.Range("C27") = rng
ActiveSheet.Name = Range("F26") & "-" & ThisWorkbook.Sheets.Count
ActiveSheet.Cells(27, 3).Select
End If
MsgBox "An Invoice for " & rng & " was generated.", vbOKOnly, "Athena Global Advisors, Inc"
'perform the same action here if you do not need to hide this sheet
'Sheets("Template").Visible = False
Application.DisplayAlerts = True
answer = MsgBox("Do you wish to save Invoice# " & Range("f26") & "?", _
vbYesNo + vbQuestion, "Athena Global Advisors, Inc")
If answer = vbYes Then
PDFActiveSheet
If answer = vbNo Then
Exit Sub
End If
End If
End Sub
Private Sub PDFActiveSheet()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), ActiveSheet.Range("F26") & "_" & ActiveSheet.Range("C27"))
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")
'create default name for savng file
strFile = ActiveSheet.Range("F26") & "_" & ActiveSheet.Range("C27") & ".pdf"
strPathFile = strPath & strFile
'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
'export to PDF if a folder was selected
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'confirmation message with file info
MsgBox "PDF file has been created: " & vbCrLf & myFile, , "Athena Global Advisors, Inc"
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub