PDA

View Full Version : Workbook Sequencing Only on Saves



BIGMOOSE88
06-03-2010, 08:47 PM
Hey Guys and Gals Ive been practicing with VB lately and let me tell you this stuff is pretty interesting, how much do programmers make anyway??

I wrote a bit of code and it works fine and everything but it seems to do the job only slightly...



Option Explicit
Private Sub Workbook_Open()
Sheets("Sheet1").Range("A1").Value = Sheets("Sheet1").Range("A1").Value + 1
ThisWorkbook.Save
End Sub



I am using this to create a purchase ordering system since quickbooks is too overwhelming..I would like it to only sequence on saves so that I could have an accurate count of orders at the end of every month..with this code itll sequence regardless if I save or not, do you think you can help? Thanks!!

Jan Karel Pieterse
06-04-2010, 01:07 AM
Try this:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("Sheet1").Range("A1").Value = Sheets("Sheet1").Range("A1").Value + 1
End Sub

(also in the thissworkbook module, remove the Open event you currently have)

BIGMOOSE88
06-04-2010, 01:28 PM
It works like a charm, Super Thanks!!