run-time error 91

  • Thread starter Thread starter sandra
  • Start date Start date
S

sandra

Hello,
I'm a newbie.

I've got a blank invoice set-up to count with the
following (so each time the blank one's opened, the next
available number comes up)

Private Sub Workbook_Open()
With Sheets(1).Range("K5")
.Value = .Value + 1
ThisWorkbook.Save
End With

End Sub

The thing is, I don't want it to count anymore if someone
does a save as. So, say someone brings up blank invoice
#101, fills it out and saves as Smith job; the next time
they open Smith job, it should still be #101. I'm stuck
at

Private Sub Workbook_Open()

Dim Book As Workbook
If Book.Name = "Test" Then
With Sheets(1).Range("K5")
.Value = .Value + 1
Book.Save
End With
End If
End Sub

My book's not helping me on this one. TIA!
 
Hi Sandra
you may try the following. If your blank invoice book is named
'Invoice_Template' try
Private Sub Workbook_Open()
if Me.Name <>"Invoice_Template.xls" then exit sub
With Sheets(1).Range("K5")
.Value = .Value + 1
ThisWorkbook.Save
End With

End Sub
 

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

Back
Top