okay. i already had the how i wanted it everything works as follows.
i wrote the macros for the work order number to generate once the service order is opened and and then it has a few buttons one button is save and the other is create PDF.
when you press the save button the auto generate macro deletes itself and the button and it user cell data and the work order number to make the file name in which its saved that way once i do that and email it the button will not be there and the number will not change.. secondly i have a button that will automatically create a PDF the the same file name. once the button is pressed it deletes itself befor generating the PDF that way you don't see the button on the PDF. all works good oh and its set to save as 97-2003 file type.
heres the issue i was now asked to make to so that it has a work order number range. so right now is references a note made file on my root drive called settings and it can be any number if i open the file and type 400 and save it then open my service order template it will generate 401 and that number will be saved into the settings folder that way the next time it will be 402.
i want to make it so the user can put a starting and finishing number into the settings folder and write the macro so that when it gets to say the (current number = >(max number - 20) then let the user know its time for updated ticket numbers..
Workbook macro
Public Sub Workbook_Open() ThisWorkbook.Sheets(1).Range("H8").Value = NextSeqNumber Call DeleteWorkbookEventCode End Sub Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long Const sDEFAULT_PATH As String = "c:" Const sDEFAULT_FNAME As String = "settings.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 Sub Main2() Call DeleteButton2 Call SvMe End Sub Sub DeleteButton1() Dim Btn As Object ActiveSheet.Shapes("Button 1 ").Delete End Sub Sub DeleteButton2() Dim Btn As Object ActiveSheet.Shapes("Button 2 ").Delete End Sub Sub DeleteWorkbookEventCode() With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule .DeleteLines 1, 33 End With End Sub Sub SvMe() 'Save filename as value of H8(ticket Number) plus Michael Plus The Value Of B8(Customer Name) Plus the current date Dim newFile As String, fName As String, cName As String On Error GoTo Skip fName = Range("H8").Value cName = Range("B8").Value newFile = fName & " " & "Michael" & " " & cName & " " & Format$(Date, "mm-dd-yyyy") ChDir _ "C:\Deleted for forum" ActiveWorkbook.SaveAs Filename:=newFile, FileFormat:=56 'Path must exist on Drive Skip: End Sub
Work sheet code
Sub SavePDF() Dim newFile As String, fName As String, cName As String On Error GoTo ChDir2 On Error GoTo ChDir3 fName = Range("H8").Value cName = Range("B8").Value newFile = fName & " Michael " & cName & "" & Format$(Date, "mm-dd-yyyy") ChDir _ "C:\Deleted for forum" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=newFile _ , Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True ChDir2: ChDir _ "C:\Deleted for forum" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=newFile _ , Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True ChDir3: ChDir _ "C:\Deleted for forum" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=newFile _ , Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks