compile error wrong number of arguments or invalid property assignment.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
765
Hello friends, hope all is well!

Please help me; I keep getting the error:

compile error wrong number of arguments or invalid property assignment.
the word Kill is highlighted in yellow.

thank you very much in advance!

Code:
Private Sub Workbook_Open()
 Dim sht As Object
   
 Dim Edate As Date
 Edate = Format("" & Sheets("Introduction.").Range("h28").Value&, "DD/MM/YYYY") ' Replace this with the date you want
 If Date > Edate + 2 Then

Application.DisplayAlerts = False
ThisWorkbook.ChangeFileAccess xlReadOnly
Kill ThisWorkbook.FullName
ThisWorkbook.Close False

End If
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Do you actually want to kill, i.e. delete the workbook? If so you probably want to set the saved property to True before actioning file-icide.
 
Upvote 0
You cannot Kill thisworkbook, because it's open.
 
Upvote 0
OK

Code:
Private Sub Workbook_Open()
Dim sht As Object
  
Dim Edate As Date
Edate = Format("" & Sheets("Introduction.").Range("h28").Value&, "DD/MM/YYYY") ' Replace this with the date you want
If Date > Edate + 2 Then


Application.DisplayAlerts = False
With ThisWorkbook
    .ChangeFileAccess xlReadOnly
    .Saved = True
    Kill .FullName
    .Close False
End With
End If
End Sub

Thisworkbook will be gone without a trace, when it opens (subject to your if condition)
 
Last edited:
Upvote 0
May I ask for one more request, please.

I want to place a time limit instead of date limit. i.e. can you please help me edit the below line in, and give the user a 4 hour limit instead?

Thanks a lot again!

Code:
Dim Edate As Date
Edate = Format("" & Sheets("Introduction.").Range("h28").Value&, "DD/MM/YYYY") ' Replace this with the date you want
If Date > Edate + 2 Then
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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