Is it possible to change this VBA code to have a three option Pop Up Message. Yes to…
- User
Is it possible to change this VBA code to have a three option Pop Up Message. Yes to call the module "ServiceProvidersHistory" No to Do nothing Open to open Workbooks.Open("G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\Service Providers History.xlsx")
If Target.Address = "$C$2" Then Dim response As Integer response = MsgBox("This process will copy all existing completed Tasks to the next Uncompleted Task" & vbCrLf & _ "and paste the copy into workbook ‘Service Providers History’." & vbCrLf & _ "After the paste, all copied Tasks will be deleted." & vbCrLf & vbCrLf & _ "Would you like to continue?" & vbCrLf & vbCrLf & _ "This process takes about 60 seconds", vbQuestion + vbYesNo, "Confirmation") If response = vbYes Then ' Call the module "ServiceProvidersHistory" Call Module22.ServiceProvidersHistory End If End If - Assistant
Yes, it is possible to change the VBA code to have a three-option Pop Up message. Here is an updated version of the code:
If Target.Address = "$C$2" Then Dim response As Integer response = MsgBox("This process will copy all existing completed Tasks to the next Uncompleted Task" & vbCrLf & _ "and paste the copy into workbook 'Service Providers History'." & vbCrLf & _ "After the paste, all copied Tasks will be deleted." & vbCrLf & vbCrLf & _ "Please choose an option:" & vbCrLf & vbCrLf & _ "Yes - Call the module 'ServiceProvidersHistory'" & vbCrLf & _ "No - Do nothing" & vbCrLf & _ "Open - Open 'Service Providers History.xlsx'", vbQuestion + vbYesNoCancel, "Confirmation") If response = vbYes Then ' Call the module "ServiceProvidersHistory" Call Module22.ServiceProvidersHistory ElseIf response = vbOpen Then Workbooks.Open("G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\Service Providers History.xlsx") End If End If - User
the variable vbOpen is not defined
- Assistant
Apologies for the confusion. The variable
vbOpendoesn't exist in VBA. However, you can use a custom value to represent the "Open" option. Here's the updated code:If Target.Address = "$C$2" Then Dim response As Integer response = MsgBox("This process will copy all existing completed Tasks to the next Uncompleted Task" & vbCrLf & _ "and paste the copy into workbook 'Service Providers History'." & vbCrLf & _ "After the paste, all copied Tasks will be deleted." & vbCrLf & vbCrLf & _ "Please choose an option:" & vbCrLf & vbCrLf & _ "Yes - Call the module 'ServiceProvidersHistory'" & vbCrLf & _ "No - Do nothing" & vbCrLf & _ "Open - Open 'Service Providers History.xlsx'", vbQuestion + vbYesNoCancel, "Confirmation") If response = vbYes Then ' Call the module "ServiceProvidersHistory" Call Module22.ServiceProvidersHistory ElseIf response = vbRetry Then Workbooks.Open("G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\Service Providers History.xlsx") End If End If - User
The pop up has three options Yes, No and Cancel. Yes runs the module, No and Cancel do nothing. I want No to open the workbook and Cancel to Exit the sub
- Assistant
Apologies for the confusion. Here's the updated code with the desired functionality:
If Target.Address = "$C$2" Then Dim response As Integer response = MsgBox("This process will copy all existing completed Tasks to the next Uncompleted Task" & vbCrLf & _ "and paste the copy into workbook 'Service Providers History'." & vbCrLf & _ "After the paste, all copied Tasks will be deleted." & vbCrLf & vbCrLf & _ "Please choose an option:" & vbCrLf & vbCrLf & _ "Yes - Call the module 'ServiceProvidersHistory'" & vbCrLf & _ "No - Open 'Service Providers History.xlsx'" & vbCrLf & _ "Cancel - Exit the sub", vbQuestion + vbYesNoCancel, "Confirmation") If response = vbYes Then ' Call the module "ServiceProvidersHistory" Call Module22.ServiceProvidersHistory ElseIf response = vbNo Then Workbooks.Open("G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\Service Providers History.xlsx") ElseIf response = vbCancel Then Exit Sub End If End If - User
If Target.Address = "2" Then Dim response As Integer response = MsgBox("This process will copy all existing completed Tasks to the next Uncompleted Task" & vbCrLf & _ "and paste the copy into workbook 'Service Providers History'." & vbCrLf & _ "After the paste, all copied Tasks will be deleted." & vbCrLf & vbCrLf & _ "Please choose an option:" & vbCrLf & vbCrLf & _ "Yes - Save Completed Tasks to History'" & vbCrLf & _ "No - View Saved Task History" & vbCrLf & _ "Cancel - Cancel and do Nothing", vbQuestion + vbYesNoCancel, "Confirmation") If response = vbYes Then ' Call the module "ServiceProvidersHistory" Call Module22.ServiceProvidersHistory
- Assistant
Apologies for the oversight. The error occurs because the "historyWB" object is not set to the opened workbook "Service Providers History.xlsx" before performing operations on it. Here's the updated code to address this issue:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.