Hey there,
For the question you asked me in your message.
Add the following two lines
ThisWorkbook.Save
ThisWorkbook.Close
Below the code
Sub txtinputbox()
Dim str As String
str = InputBox(Prompt:="Enter Job Name." & vbNewLine & "Job Name must be text not numerical", Title:="JOB NAME") 'inputbox asking for user to enter job name
If str = vbNullString Then 'if nothing is entered then
If MsgBox("Job Name not entered, would you like to enter a job name?", vbYesNo) = vbNo Then 'ask if user would like to enter job name, if they select no then
So that the entire code looks like this
Option Explicit
Global i As Long
Sub txtinputbox()
Dim str As String
str = InputBox(Prompt:="Enter Job Name." & vbNewLine & "Job Name must be text not numerical", Title:="JOB NAME") 'inputbox asking for user to enter job name
If str = vbNullString Then 'if nothing is entered then
If MsgBox("Job Name not entered, would you like to enter a job name?", vbYesNo) = vbNo Then 'ask if user would like to enter job name, if they select no then
ThisWorkbook.Save
ThisWorkbook.Close
Else
txtinputbox 'run this macro again to give user inputbox again
End If
ElseIf IsNumeric(str) Then 'if the user enters a number then
MsgBox "You have entered an invalid Job Name." & vbNewLine & "Job Name must be text", vbOKOnly 'tell them to enter a job name text only
txtinputbox 'rerun this macro to provide user with inputbox again
Else
With Sheets("Sheet1") 'with the worksheet sheet1
.Range("Job_Name").Value = str 'set the named range Job_Name equal to the value entered into the input box
.Range("A1").Value = 2 'enters the number 2 into A1 to place as a reference that the code has been run and for the on open event for this workbook
End With 'end with
'the new workbook will be saved in the same folder this workbook is saved in (defined in the Thisworkbook.path)
With ThisWorkbook 'save this workbook as the named range Job_Name value and the current data and time
.SaveAs Filename:= _
ThisWorkbook.Path & "/" & Range("Job_Name").Value & "_" & VBA.Format(VBA.Now, "mm_d_yyyy (h_mm)") & ".xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End With
End If
End Sub
Bookmarks