Disable button after a certain date and time.

avisoft20

Board Regular
Joined
Sep 10, 2016
Messages
64
Hi All ,
Code is working for email.But while insert code for Button disable after a given date period , Button is not disabled.
VBA Code:
Sub Button1_Click()
Macros_ExpirationExceeded = Date >= #7/23/2021# 'mm/dd/yyyy'
email
End Function

Public Function email()
Dim fnum As Integer
Dim lnum As Integer
lnum = 1
Dim tt1 As String
Dim tt2 As String

For fnum = 1 To lnum
  tt1 = "b" & fnum
  tt2 = "a" & fnum
  tt3 = "c" & fnum
  tt4 = "d" & fnum
 
esub = Range(tt4).Value
sendto = Range(tt1).Value
fname = Range(tt2).Value
cc = Range(tt3).Value
Set app = CreateObject("Outlook.Application")
Set itm = app.createitem(0)
With itm
 .Subject = esub
 .to = sendto
 .cc = cc
 .attachments.Add (fname)

 .display
 .send
End With
Set app = Nothing
Set itm = Nothing

Next fnum


Thanks & Regards,
Avisoft20


End Function
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Change your macro "Button1_Click" to this:
VBA Code:
Sub Button1_Click()
    Macros_ExpirationExceeded = Date >= #7/23/2021# 'mm/dd/yyyy'
    If Macros_ExpirationExceeded Then Exit Sub     '<- added
    email
End Sub
 
Upvote 0
Change your macro "Button1_Click" to this:
VBA Code:
Sub Button1_Click()
    Macros_ExpirationExceeded = Date >= #7/23/2021# 'mm/dd/yyyy'
    If Macros_ExpirationExceeded Then Exit Sub     '<- added
    email
End Sub
Thank Mr Rollis13 .
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top