LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Autonumber Newbie Assistance... Please

An invoice is created from an xlt template, details completed, and then
saved as an xls "invoice" file.

I found the following code with Google, and am running it from a button to
create an invoice auto number sequence.

Public Function NextSeqNumber(Optional sFileName As String, Optional
nSeqNumber As Long = -1) As Long
Const sDEFAULT_PATH As String = "Z:\Path..."
Const sDEFAULT_FNAME As String = "maccwktpnum.txt"
Dim nFileNumber As Long

nFileNumber = FreeFile
If sFileName = "" Then sFileName = sDEFAULT_FNAME
If InStr(sFileName, Application.PathSeparator) = 0 Then _
sFileName = sDEFAULT_PATH & Application.PathSeparator &
sFileName
If nSeqNumber = -1& Then
If Dir(sFileName) < "" Then
Open sFileName For Input As nFileNumber
Input #nFileNumber, nSeqNumber
nSeqNumber = nSeqNumber + 1&
Close nFileNumber
Else
nSeqNumber = 1&
End If
End If
On Error GoTo PathError
Open sFileName For Output As nFileNumber
On Error GoTo 0
Print #nFileNumber, nSeqNumber
Close nFileNumber
NextSeqNumber = nSeqNumber
Exit Function
PathError:
NextSeqNumber = -1&
End Function

Public Sub num()
ThisWorkbook.Sheets(1).Range("I12").Value = NextSeqNumber
End Sub


All is well with this, and it does the job. However I have identified a
operational weakness in that a new number is incremented every time the
button is pressed......As it should do.....but operationally a nightmare.
The macro is also resident and available in the saved xls invoice, so again
risks are present when the invoice is viewed.

How can I modify the above to run once only, when the invoice template is
used, or even better erase / disable the button or macro after it has been
clicked once.

I did find..

Private Sub CommandButton1_Click()
Worksheets("sheet1").Range("a1:a1").Value = "Hello World"
Worksheets("sheet1").CommandButton1.Enabled = False
End Sub

from a Google, but am unsure how to incorporate it!!!!

Ideally if the macro can be erased then will the completed invoice, saved as
an xls, not have the enable macro prompt each time the file is opened to
view?

TIA
Andy



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to set up an AutoNumber in Excel? Chris Excel Worksheet Functions 1 September 19th 07 02:22 AM
Can Excel AutoNumber Globe Director Excel Discussion (Misc queries) 3 July 27th 06 09:48 AM
lookup and autonumber rajeshparikh64 Excel Worksheet Functions 2 March 26th 06 11:19 AM
autonumber Hardy Excel Discussion (Misc queries) 4 November 24th 05 05:40 PM
How can I autonumber in excel? Tracy Excel Discussion (Misc queries) 2 August 22nd 05 08:50 PM


All times are GMT +1. The time now is 07:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"