0% found this document useful (0 votes)
14 views6 pages

EOSB Final Macro Oct-2021

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

EOSB Final Macro Oct-2021

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

'This macro is written by Vijayaraghavan Panneerselvam for EOSB Calculation

automation to PDF file in the share drive directory


'Please don't do any changes without permission to avoid any malfunction in program
'Do not enter data in formulated area in excel sheet, use only drop down list
whereever applicable

Function ntow(ByVal MyNumber)


Dim Dirham, Fils, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert Fils and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Fils = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dirham = Temp & Place(Count) & Dirham
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dirham
Case ""
Dirham = "No Dirham"
Case "One"
Dirham = "One Dollar"
Case Else
Dirham = Dirham & " Dirham"
End Select
Select Case Fils
Case ""
Fils = " and No Fils"
Case "One"
Fils = " and One Cent"
Case Else
Fils = " and " & Fils & " Fils"
End Select
ntow = Dirham
End Function

' Converts a number from 100-999 into text


Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function

' Converts a number from 10 to 99 into text.


Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result & GetDigit _
(Right(TensText, 1)) ' Retrieve ones place.
End If
GetTens = Result
End Function

' Converts a number from 1 to 9 into text.


Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function

Function Addth(pNumber As String) As String


'UpdatebyExtendoffice20160628
Select Case CLng(VBA.Right(pNumber, 1))
Case 1
Addth = pNumber & "st"
Case 2
Addth = pNumber & "nd"
Case 3
Addth = pNumber & "rd"
Case Else
Addth = pNumber & "th"
End Select
Select Case VBA.CLng(VBA.Right(pNumber, 2))
Case 11, 12, 13
Addth = pNumber & "th"
End Select
End Function
Function sst(myDate As Date)
Dim dDate As Integer
Dim dText As String
Dim mDate As Integer
Dim mmmText As String

dDate = day(myDate)
mDate = Month(myDate)

Select Case dDate


Case 1: dText = "st"
Case 2: dText = "nd"
Case 3: dText = "rd"
Case 21: dText = "st"
Case 22: dText = "nd"
Case 23: dText = "rd"
Case 31: dText = "st"
Case Else: dText = "th"
End Select

Select Case mDate


Case 1: mmmText = " January"
Case 2: mmmText = " February"
Case 3: mmmText = " March"
Case 4: mmmText = " April"
Case 5: mmmText = " May"
Case 6: mmmText = " June"
Case 7: mmmText = " July"
Case 8: mmmText = " August"
Case 9: mmmText = " September"
Case 10: mmmText = " October"
Case 11: mmmText = " November"
Case 12: mmmText = " December"
End Select

sst = dDate & dText & mmmText


End Function

Function ssm(myDate As Date)


Dim dDate As Integer
Dim dText As String
Dim mDate As Integer
Dim mmmText As String

dDate = day(myDate)
mDate = Month(myDate)

Select Case dDate


Case 1: dText = "st"
Case 2: dText = "nd"
Case 3: dText = "rd"
Case 21: dText = "st"
Case 22: dText = "nd"
Case 23: dText = "rd"
Case 31: dText = "st"
Case Else: dText = "th"
End Select

Select Case mDate


Case 1: mmmText = " January"
Case 2: mmmText = " February"
Case 3: mmmText = " March"
Case 4: mmmText = " April"
Case 5: mmmText = " May"
Case 6: mmmText = " June"
Case 7: mmmText = " July"
Case 8: mmmText = " August"
Case 9: mmmText = " September"
Case 10: mmmText = " October"
Case 11: mmmText = " November"
Case 12: mmmText = " December"
End Select

'sst = dDate & dText & mmmText


ssm = mmmText
End Function
Sub Button2_Click()
ThisWorkbook.Sheets("EOSB").Unprotect "eversendai@123"

Dim strGenericFilePath As String: strGenericFilePath = "\\192.168.5.4\groups\


HR & Admin\HR\EOSB Template\Computed EOSB\"
Dim strYear As String: strYear = Year(Date) & "\"
Dim strMonth As String: strMonth = Format(Date, "MM-") &
MonthName(Month(Date)) & "\"
Dim strDay As String: strDay = Format(Date, "DD-MMM-YYYY") & "\"
Dim PSDetails As String

If Len(Dir(strGenericFilePath & strYear, vbDirectory)) = 0 Then


MkDir strGenericFilePath & strYear
End If

If Len(Dir(strGenericFilePath & strYear & strMonth, vbDirectory)) = 0 Then


MkDir strGenericFilePath & strYear & strMonth
End If
If Len(Dir(strGenericFilePath & strYear & strMonth & strDay, vbDirectory)) = 0 Then
MkDir strGenericFilePath & strYear & strMonth & strDay
End If

If Range("G36") = "" Then


PSDetails = InputBox("Please enter the Last month Salary, if not paid",
"MyInputTitle", "Enter Last month salary amount or Status, here")
If PSDetails <> "" Then
Range("P_Month") = PSDetails
Else
MsgBox "Required DATA missing, please check and process again!"
End If

Else

If Range("I4").Value = "Staff" And Range("N10").Value = "Hide" Then

Cells(35, 35).EntireRow.Hidden = True


Cells(40, 40).EntireRow.Hidden = True
Cells(41, 41).EntireRow.Hidden = True
Else
If Range("I4").Value = "Staff" And Range("N10").Value = "Show" Then

Cells(35, 35).EntireRow.Hidden = False


Cells(40, 40).EntireRow.Hidden = True
Cells(41, 41).EntireRow.Hidden = True
Else
If Range("I4").Value = "Worker" And Range("N8").Value = "Show" Then
Cells(35, 35).EntireRow.Hidden = False
Cells(40, 40).EntireRow.Hidden = False
Cells(41, 41).EntireRow.Hidden = False
Else
If Range("I4").Value = "Worker" And Range("N8").Value = "Hide" Then
Cells(35, 35).EntireRow.Hidden = True
Cells(40, 40).EntireRow.Hidden = False
Cells(41, 41).EntireRow.Hidden = False
End If

End If
End If
End If

If Range("G38").Value = "" Then


Cells(38, 38).EntireRow.Hidden = True
Else
Cells(39, 39).EntireRow.Hidden = False
End If
If Range("G39").Value = "" Then
Cells(39, 39).EntireRow.Hidden = True
Else
Cells(39, 39).EntireRow.Hidden = False
End If

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strGenericFilePath &


strYear & "\" & strMonth & "\" & strDay & "\" & Range("XFC1").Value,
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False,
OpenAfterPublish:=True
Cells(35, 39).EntireRow.Hidden = False
Cells(36, 39).EntireRow.Hidden = False
Cells(37, 40).EntireRow.Hidden = False
Cells(38, 40).EntireRow.Hidden = False
Cells(39, 40).EntireRow.Hidden = False
Cells(40, 40).EntireRow.Hidden = False
Cells(41, 40).EntireRow.Hidden = False

Range("C3").ClearContents
Range("D36").ClearContents
Range("D39").ClearContents
Range("G29").ClearContents
Range("G31").ClearContents
Range("G36").ClearContents
Range("G38").ClearContents
Range("G39").ClearContents
Range("G45").ClearContents
Range("G46").ClearContents
Range("G47").ClearContents
Range("G48").ClearContents

ThisWorkbook.Sheets("EOSB").Protect "eversendai@123"
Range("C3").Select

End If
End Sub

You might also like