Monday, January 26, 2009

Subaru suspension

Last Friday the Subaru broke the front stabilizer bar. Check out the link for more.
http://www.ultimatesubaru.org/forum/showthread.php?p=625746&mode=threaded#post625746

Monday, January 12, 2009

Auto Increment ID numbers in Excel Templates

Today at work I needed to make an Excel template for a form that had an incrementing ID number on it. I needed the ID number to increase by 1 each time that the template was opened. After searching around awhile, I found this page that showed what event to use in the template so that the template would be modified before the new workbook that is a copy of it is created.

If you are using Excel 2007, you will have to save your template as a Macro-Enable Template (*.xltm) file or else this won't work.

I'm running 2007 and I tried modifying the template file and saving it before the new workbook is created, but Excel treated the template as a macro-disabled file when I tried to save even though the file was saved as xltm. As a result, I had to save the ID to a text file.

Place this code in the Workbook_Open() sub of ThisWorkbook:

On Error GoTo errh
'Read the file to get the current number
Dim FilePath As String
Dim MsgObj As Object, fs As Object
Dim rnum As String
Dim rnumnew As Integer

'Change this to your filepath
FilePath = "\\atgfps01\DATA\Accounting\Forms\currentid.txt"
Set fs = CreateObject("Scripting.FileSystemObject")
Set MsgObj = fs.OpenTextFile(FilePath, 1, 0) 'TristateFalse=0

rnum = MsgObj.ReadAll
rnumnew = CInt(rnum) + 1

'Change A1 to the cell holding your id number
ActiveSheet.Range("A1").Value = rnumnew

'Save over the file with the new number
Open FilePath For Output As #1
Print #1, rnumnew
Close #1

errh:
If Err.Number = 53 Then
MsgBox "The file that holds the current id is missing. It may have been renamed, moved, or deleted. It should be called " & FilePath, vbCritical, "Error"
End If