Validatefile Vba

  • July 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Validatefile Vba as PDF for free.

More details

  • Words: 217
  • Pages: 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

Related Documents

Validatefile Vba
June 2020 10
Vba Word.docx
December 2019 18
Vba Course
May 2020 5
Standard Vba
May 2020 14
Vba Combo
October 2019 39
Usando Vba
November 2019 22