Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50079

Need to Save current sheet to one of two files depending on data ( Q or I)

$
0
0
Hi there,

I have some code below that converts the current sheet to a PDF then uses data from B16, H8 and H10 to save as its filename, then it saves it to a certain file.

What I would like it to do is :

1) Convert active sheet to PDF.
2) Use the data from cells B16,H8 and H10 to save as the filename.
3) Check to see if cell H8 contains the letter Q if true then save file to C:\Documents and Settings\carl.walker\My Documents\Quotations\.
4) Check to see if cell H8 contains the letter I if true then save file to C:\Documents and Settings\carl.walker\My Documents\Invoices\.
5) Oh and still use the IF's and msgboxes.

I'm not really sure where to start to honest so any help would be much appreciated :)

Thanks in advance
Carl

Code:

Sub SaveActivesheet()

 Const strPath As String = "C:\Documents and Settings\carl.walker\My Documents\Reports\"
 Dim strFile As String

 With Sheet2
 'check that Account Details are present (customer's name)'
 If .Range("B16").Value = "" Then
 MsgBox "Please enter Account Details by using the ADD ACCOUNT Userform provided. ", _
 vbExclamation, "Missing Account"
 
 'check that Date is present'
 ElseIf .Range("H10").Value = "" Then
 MsgBox "Please enter a date. ", _
 vbExclamation, "Missing Date"

 'check that a Quotation or Invoice number is present '
 ElseIf .Range("H8").Value = "" Then
 MsgBox "Please enter a Quotation or Invoice number. ", _
 vbExclamation, "Missing Quotation or Invoice number"

Else
strFile = .Range("B16").Value & " " & .Range("H10").Value & " " & .Range("H8").Value
 .Copy 'Copy sheet2 to a new workbook

 ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
 strPath & strFile & ".pdf", Quality:= _
 xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
 OpenAfterPublish:=False

 MsgBox "This has now been converted to PDF and has been saved in the Quotations and Invoices folder. ", _
 vbExclamation, "Successfully Saved"
 
 End If
 End With
 End Sub


Viewing all articles
Browse latest Browse all 50079

Trending Articles