A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Sure thing. I actually took it a step further and made it search for an existing file first. If there is one, use it, if not make one.
Cheers!!
Sub OpenItOrMakeIt()
Dim jobnumber As String
Dim thisfilePath As String
Dim existingfile As String
Dim thissheetname As String
Dim wbDEST As Workbook
thissheetname = ActiveSheet.Name
thisfilePath = "E:\Documents"
'---------------------------------------------------
''So you open the blank LP LOG saved on the network.
''Click the button on the sheet and the
''input box pops up and asks you for the job number.
''Type it in and click ENTER and it looks to see if
''there is a file named "[job#] LP LOG.xls" in the
''main Documents directory. If there is, it opens
''the existing one and closes this one.
''if there's not, it goes through the process of
''building the workbook just like normal, but then
''it saves this new workbook in the [job#] folder in
''the Documents directory under the name
''of "[job#] LP LOG.xls", closes the blank LP LOG
''and keeps the newly created open and active
''ready for you to start modifying.
'--------------------------------------------------
jobnumber = InputBox("Enter job number: " & jobnumber)
If jobnumber = "" Then Exit Sub
existingfile = thisfilePath & "" & jobnumber & "" & jobnumber & " LP LOG" & ".xls"
Application.ScreenUpdating = False
If Len(Dir(existingfile)) > 0 Then
Set wbDEST = Workbooks.Open(existingfile)
Application.DisplayAlerts = False
ThisWorkbook.Saved = True
If Workbooks.Count > 1 Then
ThisWorkbook.Close
Else
Application.Quit
End If
Application.DisplayAlerts = True
Else
'-----------------------------------------------------
''this is where all your standard code would be found.
''If you just had a standalone workbook, you could copy
''and paste the code here.
'-----------------------------------------------------
ActiveWorkbook.SaveAs thisfilePath & "" & jobnumber & "" & jobnumber & " LP LOG" & ".xls"
End If
End Sub