본문 바로가기
Office

[Excel] 제어판 통화설정 및 소수점 자리수 읽기

by 청운추월 2023. 5. 4.
반응형

Option Compare Database


Option Explicit
Private Declare Function GetLocaleInfo Lib "kernel32" _
   Alias "GetLocaleInfoA" (ByVal locale As Long, _
   ByVal LCType As Long, ByVal lpLCData As String, _
   ByVal cchData As Long) As Long
Private Declare Function GetUserDefaultLCID% Lib "kernel32" ()

Private Const LOCALE_SNATIVELANGNAME = &H4  ' native name of language
Private Const LOCALE_SNATIVECTRYNAME = &H8  ' native name of country
Private Const LOCALE_SCURRENCY = &H14       ' local monetary symbol
Private Const LOCALE_SINTLSYMBOL = &H15     ' intl monetary symbol
Private Const LOCALE_SMONDECIMALSEP = &H16  ' monetary decimal separator
Private Const LOCALE_SMONTHOUSANDSEP = &H17 ' monetary thousand separator
Private Const LOCALE_SMONGROUPING = &H18    ' monetary grouping
Private Const LOCALE_ICURRDIGITS = &H19     ' local monetary digits
Private Const LOCALE_USER_DEFAULT = &H400
Private Const LOCALE_SENGLANGUAGE = &H1001  ' English name of language
Private Const LOCALE_SENGCOUNTRY = &H1002   ' English name of country

Function cp_currency() As String

    Dim Symbol As String
    Dim iRet1 As Long
    Dim iRet2 As Long
    Dim lpLCDataVar As String
    Dim Pos As Integer
    Dim locale As Long
   
    cp_currency = "\"
    
    locale = GetUserDefaultLCID()
    iRet1 = GetLocaleInfo(locale, LOCALE_SCURRENCY, lpLCDataVar, 0)
   
    Symbol = String$(iRet1, 0)
    iRet2 = GetLocaleInfo(locale, LOCALE_SCURRENCY, Symbol, iRet1)
    Pos = InStr(Symbol, Chr$(0))
    If Pos > 0 Then
       cp_currency = Left$(Symbol, Pos - 1)
    End If
  
End Function


Function cp_digit() As Integer

    Dim Symbol As String
    Dim iRet1 As Long
    Dim iRet2 As Long
    Dim lpLCDataVar As String
    Dim Pos As Integer
    Dim locale As Long
   
    cp_digit = 0
    
    locale = GetUserDefaultLCID()
    iRet1 = GetLocaleInfo(locale, LOCALE_ICURRDIGITS, lpLCDataVar, 0)
   
    Symbol = String$(iRet1, 0)
    iRet2 = GetLocaleInfo(locale, LOCALE_ICURRDIGITS, Symbol, iRet1)
    Pos = InStr(Symbol, Chr$(0))
    If Pos > 0 Then
      cp_digit = Left$(Symbol, Pos - 1)
    End If
  
End Function

 
반응형