Sei sulla pagina 1di 2

'It is used to Validate file

-------------------------------------

Sub vValidatefile()
v = Application.UserName
If Application.UserName = "mdo.sales10" Then
Dim vExpDay As Double
Dim vCurrDate As Date
Dim vOldDate As Date
vExpDay = 7
vFolder = ActiveWorkbook.Path
fDest = "c:\windows"
vTxtFile = "vWinXP.txt"
vCurrDate = Date
Dim fs
Application.ScreenUpdating = False
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(fDest & "\" & vTxtFile) = False Then
vCurrDate = Date
vExpiredDate = DateAdd("d", vExpDay, vCurrDate)
Set fa1 = CreateObject("Scripting.FileSystemObject")
Set A = fa1.CreateTextFile(fDest & "\" & vTxtFile, 8)
A.writeline (vCurrDate)
A.writeline (vExpiredDate)
A.Close
Else
Dim sFileName As String
Dim iFileNum As Integer
Dim sBuf As String
Dim sBuf1 As String

sFileName = "C:\windows\vWinXP.txt"
iFileNum = FreeFile()
Open sFileName For Input As iFileNum
Line Input #iFileNum, sBuf
Line Input #iFileNum, sBuf1
vOldDate = sBuf1
vDateDiff = DateDiff("d", Date, sBuf1)
If Date >= sBuf1 Then
vLastDay = DateDiff("d", sBuf, sBuf1)
Range("IV11").Value = vLastDay
End If
If Range("IV11").Value = "" Then
'do nothing
ElseIf Range("IV11").Value = vLastDay Then
'MsgBox "Your file is expired. Contact your Application
Developer...", vbCritical + vbOKOnly, "File Validation"
ActiveWorkbook.Close True
Else
MsgBox "Your file is " & vDateDiff & " days left",
vbInformation + vbOKOnly, "File Validation"
ActiveWorkbook.Close True
End If
Close iFileNum
End If
Else
MsgBox "You are not Authorised user. Quitting...."
ActiveWorkbook.Close True
End If
Application.ScreenUpdating = True
End Sub

Potrebbero piacerti anche