Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Automatic File Name Generation

I am trying to write a Work Order entry form in Excel to simply a process and
automate what seems to be difficult for folks around here.

I have a Work Order form that has a number of data fill-in cells with other
cells protected. What I would like to do is two fold:
1) Have the spreadsheet automatically place a number in a cell called
"WorkOrderNum" that would be one more incrementally than the last file saved.
2) Have the Work Order worksheet automatically use that WorkOrderNum number
as the file name when it is saved.

The functionality is such that i'm hoping to have the non-computer users
here be able to open a single file which will automatically number itself as
outlined above and then save with the number for later reference if
necessary. Personally, I'd prefer using a single database with all these
numbers and worksheet data saved in each row/record. But, knowing how others
around here work, I don't think that will be possible.

I've poked through the Help system and read several entries here in the
forums but don't see exactly what I'm looking for. Any help or suggestions
are appreciated.
--
Steven Leuck
Builders Electric, Inc.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Automatic File Name Generation

Lets see if this variation of a theme from J.E. McGimpsey won't meet your
needs.

Use Notepad to create a file to contain your work order number. "Seed" it
with the value of the last used work order number. Save the file in the same
folder with your work order Excel file. For my example I called the file
WONums.txt

This code must go into the Workbook's _Open() event handler. To put it
there, open your work order workbook and right-click the Excel icon that is
immediately to the left of the word [File] in the menu toolbar and choose
[View Code] from the pop up list. Copy the code below and paste it into the
code window in the VB Editor that shows up. Close the VB Editor, save your
file and close it.

Next time you open it, the number in WONums.txt will be obtained,
incremented and placed into WorkOrderNum. In the code you'll see the line
that does that and I've assumed that the worksheet with that named range is
named WorkOrder. Change that sheet name as required for your workbook.

The last thing the routine does is save the workbook out into the same
folder using the work order # created as the filename.

Private Sub Workbook_Open()
Dim WONumberFile As String
Dim WONumbuffer As Integer
Dim WONum As Long

'file WONums.txt must be in same folder
'with this Excel file
'find where this file is at and use
'that path to find the WONums.txt file
WONumberFile = Left(Me.FullName, _
InStrRev(Me.FullName, Application.PathSeparator)) _
& "WONums.txt"
WONumbuffer = FreeFile()
'get the last Work Order Number used
Open WONumberFile For Input As #WONumbuffer
Input #WONumbuffer, WONum
Close #WONumbuffer
'increment last W.O.#
WONum = WONum + 1
'place new W.O.# on worksheet
'***** change worksheet name as required ****
Worksheets("WorkOrder").Range("WorkOrderNum") = WONum
'write the new number back to the WONums.txt file
WONumbuffer = FreeFile()
Open WONumberFile For Output As #WONumbuffer
Print #WONumbuffer, WONum
Close #WONumbuffer
'build new name for this file based on
'the assigned W.O.#
WONumberFile = Left(WONumberFile, _
InStrRev(WONumberFile, Application.PathSeparator)) _
& Trim(Str(WONum)) & ".xls"
'save the workbook under the new name
ThisWorkbook.SaveAs WONumberFile

End Sub


"Steven Leuck" wrote:

I am trying to write a Work Order entry form in Excel to simply a process and
automate what seems to be difficult for folks around here.

I have a Work Order form that has a number of data fill-in cells with other
cells protected. What I would like to do is two fold:
1) Have the spreadsheet automatically place a number in a cell called
"WorkOrderNum" that would be one more incrementally than the last file saved.
2) Have the Work Order worksheet automatically use that WorkOrderNum number
as the file name when it is saved.

The functionality is such that i'm hoping to have the non-computer users
here be able to open a single file which will automatically number itself as
outlined above and then save with the number for later reference if
necessary. Personally, I'd prefer using a single database with all these
numbers and worksheet data saved in each row/record. But, knowing how others
around here work, I don't think that will be possible.

I've poked through the Help system and read several entries here in the
forums but don't see exactly what I'm looking for. Any help or suggestions
are appreciated.
--
Steven Leuck
Builders Electric, Inc.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Automatic File Name Generation

I too would like to accomplish the same task as Steven Leuck, however I am
having trouble. I believe I followed exactly what you indicated but I keep
getting a Runtime Error 9. The line listed here is highlighted in yellow in
the error message.

Worksheets("WorkOrder").Range("WorkOrderNum") = WONum

Not sure what I am doing wrong, I would appreciate some help.
Could I send you my file?

Thank you,
Dane Watson



"JLatham" wrote:

Lets see if this variation of a theme from J.E. McGimpsey won't meet your
needs.

Use Notepad to create a file to contain your work order number. "Seed" it
with the value of the last used work order number. Save the file in the same
folder with your work order Excel file. For my example I called the file
WONums.txt

This code must go into the Workbook's _Open() event handler. To put it
there, open your work order workbook and right-click the Excel icon that is
immediately to the left of the word [File] in the menu toolbar and choose
[View Code] from the pop up list. Copy the code below and paste it into the
code window in the VB Editor that shows up. Close the VB Editor, save your
file and close it.

Next time you open it, the number in WONums.txt will be obtained,
incremented and placed into WorkOrderNum. In the code you'll see the line
that does that and I've assumed that the worksheet with that named range is
named WorkOrder. Change that sheet name as required for your workbook.

The last thing the routine does is save the workbook out into the same
folder using the work order # created as the filename.

Private Sub Workbook_Open()
Dim WONumberFile As String
Dim WONumbuffer As Integer
Dim WONum As Long

'file WONums.txt must be in same folder
'with this Excel file
'find where this file is at and use
'that path to find the WONums.txt file
WONumberFile = Left(Me.FullName, _
InStrRev(Me.FullName, Application.PathSeparator)) _
& "WONums.txt"
WONumbuffer = FreeFile()
'get the last Work Order Number used
Open WONumberFile For Input As #WONumbuffer
Input #WONumbuffer, WONum
Close #WONumbuffer
'increment last W.O.#
WONum = WONum + 1
'place new W.O.# on worksheet
'***** change worksheet name as required ****
Worksheets("WorkOrder").Range("WorkOrderNum") = WONum
'write the new number back to the WONums.txt file
WONumbuffer = FreeFile()
Open WONumberFile For Output As #WONumbuffer
Print #WONumbuffer, WONum
Close #WONumbuffer
'build new name for this file based on
'the assigned W.O.#
WONumberFile = Left(WONumberFile, _
InStrRev(WONumberFile, Application.PathSeparator)) _
& Trim(Str(WONum)) & ".xls"
'save the workbook under the new name
ThisWorkbook.SaveAs WONumberFile

End Sub


"Steven Leuck" wrote:

I am trying to write a Work Order entry form in Excel to simply a process and
automate what seems to be difficult for folks around here.

I have a Work Order form that has a number of data fill-in cells with other
cells protected. What I would like to do is two fold:
1) Have the spreadsheet automatically place a number in a cell called
"WorkOrderNum" that would be one more incrementally than the last file saved.
2) Have the Work Order worksheet automatically use that WorkOrderNum number
as the file name when it is saved.

The functionality is such that i'm hoping to have the non-computer users
here be able to open a single file which will automatically number itself as
outlined above and then save with the number for later reference if
necessary. Personally, I'd prefer using a single database with all these
numbers and worksheet data saved in each row/record. But, knowing how others
around here work, I don't think that will be possible.

I've poked through the Help system and read several entries here in the
forums but don't see exactly what I'm looking for. Any help or suggestions
are appreciated.
--
Steven Leuck
Builders Electric, Inc.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Automatic File Name Generation

I'm not Jerry...

Do you have a worksheet in the activeworkbook named WorkOrder?

I bet not (check for leading/trailing spaces if you think you do).

Dane wrote:

I too would like to accomplish the same task as Steven Leuck, however I am
having trouble. I believe I followed exactly what you indicated but I keep
getting a Runtime Error 9. The line listed here is highlighted in yellow in
the error message.

Worksheets("WorkOrder").Range("WorkOrderNum") = WONum

Not sure what I am doing wrong, I would appreciate some help.
Could I send you my file?

Thank you,
Dane Watson

"JLatham" wrote:

Lets see if this variation of a theme from J.E. McGimpsey won't meet your
needs.

Use Notepad to create a file to contain your work order number. "Seed" it
with the value of the last used work order number. Save the file in the same
folder with your work order Excel file. For my example I called the file
WONums.txt

This code must go into the Workbook's _Open() event handler. To put it
there, open your work order workbook and right-click the Excel icon that is
immediately to the left of the word [File] in the menu toolbar and choose
[View Code] from the pop up list. Copy the code below and paste it into the
code window in the VB Editor that shows up. Close the VB Editor, save your
file and close it.

Next time you open it, the number in WONums.txt will be obtained,
incremented and placed into WorkOrderNum. In the code you'll see the line
that does that and I've assumed that the worksheet with that named range is
named WorkOrder. Change that sheet name as required for your workbook.

The last thing the routine does is save the workbook out into the same
folder using the work order # created as the filename.

Private Sub Workbook_Open()
Dim WONumberFile As String
Dim WONumbuffer As Integer
Dim WONum As Long

'file WONums.txt must be in same folder
'with this Excel file
'find where this file is at and use
'that path to find the WONums.txt file
WONumberFile = Left(Me.FullName, _
InStrRev(Me.FullName, Application.PathSeparator)) _
& "WONums.txt"
WONumbuffer = FreeFile()
'get the last Work Order Number used
Open WONumberFile For Input As #WONumbuffer
Input #WONumbuffer, WONum
Close #WONumbuffer
'increment last W.O.#
WONum = WONum + 1
'place new W.O.# on worksheet
'***** change worksheet name as required ****
Worksheets("WorkOrder").Range("WorkOrderNum") = WONum
'write the new number back to the WONums.txt file
WONumbuffer = FreeFile()
Open WONumberFile For Output As #WONumbuffer
Print #WONumbuffer, WONum
Close #WONumbuffer
'build new name for this file based on
'the assigned W.O.#
WONumberFile = Left(WONumberFile, _
InStrRev(WONumberFile, Application.PathSeparator)) _
& Trim(Str(WONum)) & ".xls"
'save the workbook under the new name
ThisWorkbook.SaveAs WONumberFile

End Sub


"Steven Leuck" wrote:

I am trying to write a Work Order entry form in Excel to simply a process and
automate what seems to be difficult for folks around here.

I have a Work Order form that has a number of data fill-in cells with other
cells protected. What I would like to do is two fold:
1) Have the spreadsheet automatically place a number in a cell called
"WorkOrderNum" that would be one more incrementally than the last file saved.
2) Have the Work Order worksheet automatically use that WorkOrderNum number
as the file name when it is saved.

The functionality is such that i'm hoping to have the non-computer users
here be able to open a single file which will automatically number itself as
outlined above and then save with the number for later reference if
necessary. Personally, I'd prefer using a single database with all these
numbers and worksheet data saved in each row/record. But, knowing how others
around here work, I don't think that will be possible.

I've poked through the Help system and read several entries here in the
forums but don't see exactly what I'm looking for. Any help or suggestions
are appreciated.
--
Steven Leuck
Builders Electric, Inc.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Automatic File Name Generation

Thank you Dave,
I am afraid to say that I did not have the WORKS SHEET named WorkOrder, it
was the default Sheet1.
I since changed it, but the problem still occurs.

"Dave Peterson" wrote:

I'm not Jerry...

Do you have a worksheet in the activeworkbook named WorkOrder?

I bet not (check for leading/trailing spaces if you think you do).

Dane wrote:

I too would like to accomplish the same task as Steven Leuck, however I am
having trouble. I believe I followed exactly what you indicated but I keep
getting a Runtime Error 9. The line listed here is highlighted in yellow in
the error message.

Worksheets("WorkOrder").Range("WorkOrderNum") = WONum

Not sure what I am doing wrong, I would appreciate some help.
Could I send you my file?

Thank you,
Dane Watson

"JLatham" wrote:

Lets see if this variation of a theme from J.E. McGimpsey won't meet your
needs.

Use Notepad to create a file to contain your work order number. "Seed" it
with the value of the last used work order number. Save the file in the same
folder with your work order Excel file. For my example I called the file
WONums.txt

This code must go into the Workbook's _Open() event handler. To put it
there, open your work order workbook and right-click the Excel icon that is
immediately to the left of the word [File] in the menu toolbar and choose
[View Code] from the pop up list. Copy the code below and paste it into the
code window in the VB Editor that shows up. Close the VB Editor, save your
file and close it.

Next time you open it, the number in WONums.txt will be obtained,
incremented and placed into WorkOrderNum. In the code you'll see the line
that does that and I've assumed that the worksheet with that named range is
named WorkOrder. Change that sheet name as required for your workbook.

The last thing the routine does is save the workbook out into the same
folder using the work order # created as the filename.

Private Sub Workbook_Open()
Dim WONumberFile As String
Dim WONumbuffer As Integer
Dim WONum As Long

'file WONums.txt must be in same folder
'with this Excel file
'find where this file is at and use
'that path to find the WONums.txt file
WONumberFile = Left(Me.FullName, _
InStrRev(Me.FullName, Application.PathSeparator)) _
& "WONums.txt"
WONumbuffer = FreeFile()
'get the last Work Order Number used
Open WONumberFile For Input As #WONumbuffer
Input #WONumbuffer, WONum
Close #WONumbuffer
'increment last W.O.#
WONum = WONum + 1
'place new W.O.# on worksheet
'***** change worksheet name as required ****
Worksheets("WorkOrder").Range("WorkOrderNum") = WONum
'write the new number back to the WONums.txt file
WONumbuffer = FreeFile()
Open WONumberFile For Output As #WONumbuffer
Print #WONumbuffer, WONum
Close #WONumbuffer
'build new name for this file based on
'the assigned W.O.#
WONumberFile = Left(WONumberFile, _
InStrRev(WONumberFile, Application.PathSeparator)) _
& Trim(Str(WONum)) & ".xls"
'save the workbook under the new name
ThisWorkbook.SaveAs WONumberFile

End Sub


"Steven Leuck" wrote:

I am trying to write a Work Order entry form in Excel to simply a process and
automate what seems to be difficult for folks around here.

I have a Work Order form that has a number of data fill-in cells with other
cells protected. What I would like to do is two fold:
1) Have the spreadsheet automatically place a number in a cell called
"WorkOrderNum" that would be one more incrementally than the last file saved.
2) Have the Work Order worksheet automatically use that WorkOrderNum number
as the file name when it is saved.

The functionality is such that i'm hoping to have the non-computer users
here be able to open a single file which will automatically number itself as
outlined above and then save with the number for later reference if
necessary. Personally, I'd prefer using a single database with all these
numbers and worksheet data saved in each row/record. But, knowing how others
around here work, I don't think that will be possible.

I've poked through the Help system and read several entries here in the
forums but don't see exactly what I'm looking for. Any help or suggestions
are appreciated.
--
Steven Leuck
Builders Electric, Inc.


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Automatic File Name Generation

Dave's suggestion is the same one I would have made. Check the name on the
sheet tab and make sure it is exactly the same as you've typed in your code.
It is not all that unusual to find that the name on the sheet's tab is either
" WorkOrder" or "WorkOrder " instead of actually just "WorkOrder".

"Dane" wrote:

I too would like to accomplish the same task as Steven Leuck, however I am
having trouble. I believe I followed exactly what you indicated but I keep
getting a Runtime Error 9. The line listed here is highlighted in yellow in
the error message.

Worksheets("WorkOrder").Range("WorkOrderNum") = WONum

Not sure what I am doing wrong, I would appreciate some help.
Could I send you my file?

Thank you,
Dane Watson



"JLatham" wrote:

Lets see if this variation of a theme from J.E. McGimpsey won't meet your
needs.

Use Notepad to create a file to contain your work order number. "Seed" it
with the value of the last used work order number. Save the file in the same
folder with your work order Excel file. For my example I called the file
WONums.txt

This code must go into the Workbook's _Open() event handler. To put it
there, open your work order workbook and right-click the Excel icon that is
immediately to the left of the word [File] in the menu toolbar and choose
[View Code] from the pop up list. Copy the code below and paste it into the
code window in the VB Editor that shows up. Close the VB Editor, save your
file and close it.

Next time you open it, the number in WONums.txt will be obtained,
incremented and placed into WorkOrderNum. In the code you'll see the line
that does that and I've assumed that the worksheet with that named range is
named WorkOrder. Change that sheet name as required for your workbook.

The last thing the routine does is save the workbook out into the same
folder using the work order # created as the filename.

Private Sub Workbook_Open()
Dim WONumberFile As String
Dim WONumbuffer As Integer
Dim WONum As Long

'file WONums.txt must be in same folder
'with this Excel file
'find where this file is at and use
'that path to find the WONums.txt file
WONumberFile = Left(Me.FullName, _
InStrRev(Me.FullName, Application.PathSeparator)) _
& "WONums.txt"
WONumbuffer = FreeFile()
'get the last Work Order Number used
Open WONumberFile For Input As #WONumbuffer
Input #WONumbuffer, WONum
Close #WONumbuffer
'increment last W.O.#
WONum = WONum + 1
'place new W.O.# on worksheet
'***** change worksheet name as required ****
Worksheets("WorkOrder").Range("WorkOrderNum") = WONum
'write the new number back to the WONums.txt file
WONumbuffer = FreeFile()
Open WONumberFile For Output As #WONumbuffer
Print #WONumbuffer, WONum
Close #WONumbuffer
'build new name for this file based on
'the assigned W.O.#
WONumberFile = Left(WONumberFile, _
InStrRev(WONumberFile, Application.PathSeparator)) _
& Trim(Str(WONum)) & ".xls"
'save the workbook under the new name
ThisWorkbook.SaveAs WONumberFile

End Sub


"Steven Leuck" wrote:

I am trying to write a Work Order entry form in Excel to simply a process and
automate what seems to be difficult for folks around here.

I have a Work Order form that has a number of data fill-in cells with other
cells protected. What I would like to do is two fold:
1) Have the spreadsheet automatically place a number in a cell called
"WorkOrderNum" that would be one more incrementally than the last file saved.
2) Have the Work Order worksheet automatically use that WorkOrderNum number
as the file name when it is saved.

The functionality is such that i'm hoping to have the non-computer users
here be able to open a single file which will automatically number itself as
outlined above and then save with the number for later reference if
necessary. Personally, I'd prefer using a single database with all these
numbers and worksheet data saved in each row/record. But, knowing how others
around here work, I don't think that will be possible.

I've poked through the Help system and read several entries here in the
forums but don't see exactly what I'm looking for. Any help or suggestions
are appreciated.
--
Steven Leuck
Builders Electric, Inc.

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Automatic File Name Generation

Hi Jerry I just replied to Dave, as you can see I am still having the same
problem after making the corrections to the name of the work sheet. I was
also very careful to ensure that there were no leading or trailing spaces.

"JLatham" wrote:

Dave's suggestion is the same one I would have made. Check the name on the
sheet tab and make sure it is exactly the same as you've typed in your code.
It is not all that unusual to find that the name on the sheet's tab is either
" WorkOrder" or "WorkOrder " instead of actually just "WorkOrder".

"Dane" wrote:

I too would like to accomplish the same task as Steven Leuck, however I am
having trouble. I believe I followed exactly what you indicated but I keep
getting a Runtime Error 9. The line listed here is highlighted in yellow in
the error message.

Worksheets("WorkOrder").Range("WorkOrderNum") = WONum

Not sure what I am doing wrong, I would appreciate some help.
Could I send you my file?

Thank you,
Dane Watson



"JLatham" wrote:

Lets see if this variation of a theme from J.E. McGimpsey won't meet your
needs.

Use Notepad to create a file to contain your work order number. "Seed" it
with the value of the last used work order number. Save the file in the same
folder with your work order Excel file. For my example I called the file
WONums.txt

This code must go into the Workbook's _Open() event handler. To put it
there, open your work order workbook and right-click the Excel icon that is
immediately to the left of the word [File] in the menu toolbar and choose
[View Code] from the pop up list. Copy the code below and paste it into the
code window in the VB Editor that shows up. Close the VB Editor, save your
file and close it.

Next time you open it, the number in WONums.txt will be obtained,
incremented and placed into WorkOrderNum. In the code you'll see the line
that does that and I've assumed that the worksheet with that named range is
named WorkOrder. Change that sheet name as required for your workbook.

The last thing the routine does is save the workbook out into the same
folder using the work order # created as the filename.

Private Sub Workbook_Open()
Dim WONumberFile As String
Dim WONumbuffer As Integer
Dim WONum As Long

'file WONums.txt must be in same folder
'with this Excel file
'find where this file is at and use
'that path to find the WONums.txt file
WONumberFile = Left(Me.FullName, _
InStrRev(Me.FullName, Application.PathSeparator)) _
& "WONums.txt"
WONumbuffer = FreeFile()
'get the last Work Order Number used
Open WONumberFile For Input As #WONumbuffer
Input #WONumbuffer, WONum
Close #WONumbuffer
'increment last W.O.#
WONum = WONum + 1
'place new W.O.# on worksheet
'***** change worksheet name as required ****
Worksheets("WorkOrder").Range("WorkOrderNum") = WONum
'write the new number back to the WONums.txt file
WONumbuffer = FreeFile()
Open WONumberFile For Output As #WONumbuffer
Print #WONumbuffer, WONum
Close #WONumbuffer
'build new name for this file based on
'the assigned W.O.#
WONumberFile = Left(WONumberFile, _
InStrRev(WONumberFile, Application.PathSeparator)) _
& Trim(Str(WONum)) & ".xls"
'save the workbook under the new name
ThisWorkbook.SaveAs WONumberFile

End Sub


"Steven Leuck" wrote:

I am trying to write a Work Order entry form in Excel to simply a process and
automate what seems to be difficult for folks around here.

I have a Work Order form that has a number of data fill-in cells with other
cells protected. What I would like to do is two fold:
1) Have the spreadsheet automatically place a number in a cell called
"WorkOrderNum" that would be one more incrementally than the last file saved.
2) Have the Work Order worksheet automatically use that WorkOrderNum number
as the file name when it is saved.

The functionality is such that i'm hoping to have the non-computer users
here be able to open a single file which will automatically number itself as
outlined above and then save with the number for later reference if
necessary. Personally, I'd prefer using a single database with all these
numbers and worksheet data saved in each row/record. But, knowing how others
around here work, I don't think that will be possible.

I've poked through the Help system and read several entries here in the
forums but don't see exactly what I'm looking for. Any help or suggestions
are appreciated.
--
Steven Leuck
Builders Electric, Inc.

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Automatic File Name Generation

email me the workbook and I'll see if I can figure out what is not there that
needs to be. Make sure that you also have a range named WorkOrderNum in the
workbook.

email to (remove spaces) HelpFrom @ jlathamsite.com and I'll get it.

"Dane" wrote:

Hi Jerry I just replied to Dave, as you can see I am still having the same
problem after making the corrections to the name of the work sheet. I was
also very careful to ensure that there were no leading or trailing spaces.

"JLatham" wrote:

Dave's suggestion is the same one I would have made. Check the name on the
sheet tab and make sure it is exactly the same as you've typed in your code.
It is not all that unusual to find that the name on the sheet's tab is either
" WorkOrder" or "WorkOrder " instead of actually just "WorkOrder".

"Dane" wrote:

I too would like to accomplish the same task as Steven Leuck, however I am
having trouble. I believe I followed exactly what you indicated but I keep
getting a Runtime Error 9. The line listed here is highlighted in yellow in
the error message.

Worksheets("WorkOrder").Range("WorkOrderNum") = WONum

Not sure what I am doing wrong, I would appreciate some help.
Could I send you my file?

Thank you,
Dane Watson



"JLatham" wrote:

Lets see if this variation of a theme from J.E. McGimpsey won't meet your
needs.

Use Notepad to create a file to contain your work order number. "Seed" it
with the value of the last used work order number. Save the file in the same
folder with your work order Excel file. For my example I called the file
WONums.txt

This code must go into the Workbook's _Open() event handler. To put it
there, open your work order workbook and right-click the Excel icon that is
immediately to the left of the word [File] in the menu toolbar and choose
[View Code] from the pop up list. Copy the code below and paste it into the
code window in the VB Editor that shows up. Close the VB Editor, save your
file and close it.

Next time you open it, the number in WONums.txt will be obtained,
incremented and placed into WorkOrderNum. In the code you'll see the line
that does that and I've assumed that the worksheet with that named range is
named WorkOrder. Change that sheet name as required for your workbook.

The last thing the routine does is save the workbook out into the same
folder using the work order # created as the filename.

Private Sub Workbook_Open()
Dim WONumberFile As String
Dim WONumbuffer As Integer
Dim WONum As Long

'file WONums.txt must be in same folder
'with this Excel file
'find where this file is at and use
'that path to find the WONums.txt file
WONumberFile = Left(Me.FullName, _
InStrRev(Me.FullName, Application.PathSeparator)) _
& "WONums.txt"
WONumbuffer = FreeFile()
'get the last Work Order Number used
Open WONumberFile For Input As #WONumbuffer
Input #WONumbuffer, WONum
Close #WONumbuffer
'increment last W.O.#
WONum = WONum + 1
'place new W.O.# on worksheet
'***** change worksheet name as required ****
Worksheets("WorkOrder").Range("WorkOrderNum") = WONum
'write the new number back to the WONums.txt file
WONumbuffer = FreeFile()
Open WONumberFile For Output As #WONumbuffer
Print #WONumbuffer, WONum
Close #WONumbuffer
'build new name for this file based on
'the assigned W.O.#
WONumberFile = Left(WONumberFile, _
InStrRev(WONumberFile, Application.PathSeparator)) _
& Trim(Str(WONum)) & ".xls"
'save the workbook under the new name
ThisWorkbook.SaveAs WONumberFile

End Sub


"Steven Leuck" wrote:

I am trying to write a Work Order entry form in Excel to simply a process and
automate what seems to be difficult for folks around here.

I have a Work Order form that has a number of data fill-in cells with other
cells protected. What I would like to do is two fold:
1) Have the spreadsheet automatically place a number in a cell called
"WorkOrderNum" that would be one more incrementally than the last file saved.
2) Have the Work Order worksheet automatically use that WorkOrderNum number
as the file name when it is saved.

The functionality is such that i'm hoping to have the non-computer users
here be able to open a single file which will automatically number itself as
outlined above and then save with the number for later reference if
necessary. Personally, I'd prefer using a single database with all these
numbers and worksheet data saved in each row/record. But, knowing how others
around here work, I don't think that will be possible.

I've poked through the Help system and read several entries here in the
forums but don't see exactly what I'm looking for. Any help or suggestions
are appreciated.
--
Steven Leuck
Builders Electric, Inc.

Reply
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
Automatic number generation. BM Excel Discussion (Misc queries) 1 August 14th 06 02:38 PM
Prevent automatic random generation teteperreira Excel Worksheet Functions 0 May 9th 06 09:57 PM
Automatic List Generation JerryS Excel Worksheet Functions 8 March 15th 06 07:01 PM
Automatic filename generation template Astrodude Excel Discussion (Misc queries) 0 April 6th 05 06:19 AM
Automatic Graph generation by series SiliconAlleyDude Charts and Charting in Excel 2 March 25th 05 07:15 AM


All times are GMT +1. The time now is 02:43 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"