ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If vbYes Then help... (https://www.excelbanter.com/excel-programming/298332-if-vbyes-then-help.html)

RPIJG[_21_]

If vbYes Then help...
 

Code
-------------------
Private Sub Workbook_open()
Dim ans3
ans3 = MsgBox("Do you really want to create a new invoice? Once created the Invoice number is final. ", vbYesNo)
If ans = vbYes Then
If ans = vbNo Then
Application.Quit
End If
End If
Dim InvNo&
'Do not assign new inv nbr if the original template has been opened
If UCase(Right(ThisWorkbook.Name, 3)) = "XLT" Then Exit Sub
'If O3 does not contain anything, enter the next inv nbr
If [O3] = "" Then
'Get next inv nbr
InvNo = GetSetting("XLInvoices", "Invoices", "CurrentNo", 1000) + 1
'Enter the inv nbr in A1
[O3] = InvNo
'Save the inv nbr
SaveSetting "XLInvoices", "Invoices", "CurrentNo", InvNo
'Put todays date in O4
[O4] = Date
End If
End Su
-------------------


I just want to make it so that when you click on yes it runs the cod
below, and if you click no it exits the excel

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

If vbYes Then help...
 
Private Sub Workbook_open()
Dim ans3
ans3 = MsgBox("Do you really want to create a new invoice? " & _
"Once created the Invoice number is final. ", vbYesNo)
If ans3 = vbYes Then
Dim InvNo&
'Do not assign new inv nbr if the original template has been opened
If UCase(Right(ThisWorkbook.Name, 3)) = "XLT" Then Exit Sub
'If O3 does not contain anything, enter the next inv nbr
If [O3] = "" Then
'Get next inv nbr
InvNo = GetSetting("XLInvoices", "Invoices", "CurrentNo", 1000) + 1
'Enter the inv nbr in A1
[O3] = InvNo
'Save the inv nbr
SaveSetting "XLInvoices", "Invoices", "CurrentNo", InvNo
'Put todays date in O4
[O4] = Date
End If
Else
Application.Quit
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"RPIJG " wrote in message
...

Code:
--------------------
Private Sub Workbook_open()
Dim ans3
ans3 = MsgBox("Do you really want to create a new invoice? Once created

the Invoice number is final. ", vbYesNo)
If ans = vbYes Then
If ans = vbNo Then
Application.Quit
End If
End If
Dim InvNo&
'Do not assign new inv nbr if the original template has been opened
If UCase(Right(ThisWorkbook.Name, 3)) = "XLT" Then Exit Sub
'If O3 does not contain anything, enter the next inv nbr
If [O3] = "" Then
'Get next inv nbr
InvNo = GetSetting("XLInvoices", "Invoices", "CurrentNo", 1000) + 1
'Enter the inv nbr in A1
[O3] = InvNo
'Save the inv nbr
SaveSetting "XLInvoices", "Invoices", "CurrentNo", InvNo
'Put todays date in O4
[O4] = Date
End If
End Sub
--------------------


I just want to make it so that when you click on yes it runs the code
below, and if you click no it exits the excel.


---
Message posted from http://www.ExcelForum.com/




kkknie[_95_]

If vbYes Then help...
 
Change to:


Code
-------------------
Private Sub Workbook_open()
Dim ans3
ans3 = MsgBox("Do you really want to create a new invoice? Once created the Invoice number is final. ", vbYesNo)
If ans = vbNo Then Application.Quit

'The rest of your code goes here...

End Su
-------------------




--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

If vbYes Then help...
 
Not much good returning the answer to ans3 but testing ans.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"kkknie " wrote in message
...
Change to:


Code:
--------------------
Private Sub Workbook_open()
Dim ans3
ans3 = MsgBox("Do you really want to create a new invoice? Once created

the Invoice number is final. ", vbYesNo)
If ans = vbNo Then Application.Quit

'The rest of your code goes here...

End Sub
--------------------


K


---
Message posted from http://www.ExcelForum.com/




kkknie[_96_]

If vbYes Then help...
 
Looks like a typo in the IP's post. They should probably both b
ans3...



--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

If vbYes Then help...
 
They certainly should seeing as he DIMmed ans3.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"kkknie " wrote in message
...
Looks like a typo in the IP's post. They should probably both be
ans3...

K


---
Message posted from http://www.ExcelForum.com/




RPIJG[_22_]

If vbYes Then help...
 
Thanks everyone, I figured this out just after I beat my head on a wal
repeatedly for hours. Was a great deal of fun. Thanks again.

Jo

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 05:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com