Save file macro

G

Guest

I am using the Invoice template to create new invoices.
The following SaveInvoice() macro is in PERSONAL.XLS.
The macro appears to save the PERSONAL.XLS sheet only.
I need the Invoice saved instead.
How do I modify this macro to save only the Invoice?
The filename operates correctly.
Thanks.

Sub SaveInvoice()

Dim flToSave As Variant
Dim flName As String
Dim flFormat As Long

flFormat = ActiveWorkbook.FileFormat

flName = "Invoice_" & Cells(4, 12).Value
flToSave = Application.GetSaveAsFilename _
(flName, filefilter:="Excel Files (*.xls), *.xls", Title:="Save File
As...")

If flToSave = False Then
Exit Sub
Else
ThisWorkbook.SaveAs Filename:=flToSave, FileFormat:=flFormat
End If

End Sub
 
D

Dave Peterson

ThisWorkbook really means ThisWorkbook. It's the workbook that contains the
code.

If you want to run the macro against the activeworkbook:
Activeworkbook.SaveAs Filename:=flToSave, FileFormat:=flFormat
 
G

Guest

Thank you Dave Peterson. It works great now.

Dave Peterson said:
ThisWorkbook really means ThisWorkbook. It's the workbook that contains the
code.

If you want to run the macro against the activeworkbook:
Activeworkbook.SaveAs Filename:=flToSave, FileFormat:=flFormat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top