noob: problems with macros in invoice

D

dogfeet

the posting rules said to be very specific when posting so i'll try t
be as descriptive as possible. i'm working on an invoice for a friend'
business and i'd like to add a lot of automation to the file. i go
pretty much everything working but i'm stumped on a couple of issues
this is what it does right.

1. the invoice number is set to increase each time the invoice templat
is opened (programmed in the macro).
2. the current date is automatically displayed in the date box when th
template is opened
3. when the user clicks 'save' or 'save as', it is either saved as th
invoice number, or the invoice number is the default filename in th
save as box, respectively.

the problem is this... everytime the user opens one of the previou
invoices, the macros continue to do their work. that means that whe
invoice #102 is opened, it automatically increases the invoice number
i managed to get the date to stay frozen when opening old invoices s
the problem is half solved.

here is my macro.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel A
Boolean)
Application.DisplayAlerts = False
ThisWorkbook.SaveAs ThisWorkbook.Path & "\" & _
ThisWorkbook.Worksheets("Sheet1").Range("g14").Value & _
".xls"
Application.DisplayAlerts = True
Set datehalter = Sheets("Sheet1").Range("g12")
With datehalter
.Value = Sheets("Sheet1").Range("g12")
End With
Set deincrement = Sheets("Sheet1").Range("F14")
With deincrement
.Value = 1
End With
End Sub

Sub Workbook_Open()
Set ponum = Sheets("Sheet1").Range("g14")
With ponum
.Value = .Value + 2
End With
ActiveWorkbook.Save
End Sub

to clarify any confusion, this is what's in the following cells.
g12 = date
f14 = "0" (my effort to solve the prob)
g14 = invoice number

i believe that the problem might be solved if i could find a command t
enable certain macros if the filename is numberic, and other macros i
the filename is text. any help would be greatly appreciated
 
T

Tom Ogilvy

What is guaranteed to be different between your template and an invoice.
Check that before you increment the invoice number or run any code that is
unique to when the invoice is initiated.
 
D

Dave Peterson

Maybe you could just check to see if the name matches the "master" workbook.

if lcase(thisworkbook.name) <> "master.xls" then exit sub

(at the top of each procedure that shouldn't run)

If the folder is in the same location for all users, then you could be more
specific.

if lcase(thisworkbook.fullname) <> "c:\my documents\excel\master.xls" then
exit sub
end if
 

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