Invoice Creation

vvk29

New Member
Joined
Jun 23, 2019
Messages
3
i want to making diffrent number invoice in my PC also want save pdf in my target folder
i was trying to by your coding but it change mumber but not save pdf in target folder

here that coading


Sub NextInvoice()
Range("B2").Value = Range("B2").Value + 1
Range("B9:B18").ClearContents
End Sub
Sub SaveInvoiceAsPDFAndClear()
Dim NewFN As Variant
NewFN = "C:\Users\admin\Documents\invoice copy" & Range("B2").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Range("B2").Value = Range("B2").Value + 1
Range("B9:B18").ClearContents
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Welcome to the forum :)

I tested your code and it works fine
- are you sure you are looking in the correct folder for it ? (ie did VBA save it in the that folder or somewhere else ?)

The code below is identical to yours but it is broken up to show the path being built up which makes it clearer ...

If the invoice number is 5017 then this saves Invoice Copy5017.pdf to C:\Users\admin\Documents
Code:
Sub SaveInvoiceAsPDFAndClear()
    Dim NewFN As String
[COLOR=#006400]'path where PDF to be saved[/COLOR]
    NewFN = "[COLOR=#ff0000]C:\Users\admin\Documents\[/COLOR]"
[COLOR=#006400]'next add the name of the invoice[/COLOR]
    NewFN = NewFN & "invoice copy" & Range("B2").Value & ".pdf"
[COLOR=#006400]'save the file[/COLOR]
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN
[COLOR=#006400]'increase number by 1 and clear old values[/COLOR]
    Range("B2").Value = Range("B2").Value + 1
    Range("B9:B18").ClearContents

Did you intend to save it there? or to save 5017.pdf to SUB-FOLDER Invoice Copy which would look like this
Code:
[COLOR=#006400]'path where PDF to be saved[/COLOR]
    NewFN = [COLOR=#ff0000]"C:\Users\admin\Documents\Invoice Copy\[/COLOR]"
[COLOR=#006400]'next add the name of the invoice[/COLOR]
    NewFN = NewFN & Range("B2").Value & ".pdf"
End Sub
 
Last edited:
Upvote 0
I cannot replicate your problem :confused: It has never happened to me :confused:


This is a guess!!
Test to see if the problem goes away and then we can fix the range
Code:
    ActiveSheet.Range("A1:E30").ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN


1. Did it work?

2. Are you able to specify the invoice range - is it always the same?

3. If range is not always the same ...
- which columns are in the invoice ?
- which column can VBA use to find the last row of the invoice ?
(= which column always has a value the last row ?)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top