怎么使用vba修改控制面版里的日期格式?

修改为yyyy/mm/dd格式。
给个思路也行啊!
---------------------------------------------------------------

这些设置存在注册表中 .....Control Panel\Internationa\...中,修改注册表键值即可
---------------------------------------------------------------
谢谢版主的回答,我找到了一个方法。大家有兴趣帮我测试一下!把结果贴上来!

把下面代码放到一个MODULE里,这样用:mdlChangeSystemDateFormat "yyyy/MM/dd"
注意MM一定要大写

'--------------------------------------------------------
'Purpose: Change system shortdate format
'Example: Call mdlChangeSystemDateFormat("yyyy/MM/dd")
'--------------------------------------------------------

Public Const LOCALE_SSHORTDATE As Long = &H1F
Public Const LOCALE_USER_DEFAULT As Long = &H400

Public Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal lLocale As Long, ByVal lLocaleType As Long, ByVal sLCData As String, ByVal lBufferLength As Long) As Long
Public Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long

Public Function mdlChangeSystemDateFormat(strFormat As String) As Boolean

Dim strShortDateFormat As String, strBuffer As String
Dim lBuffSize As Long, lRetVal As Long

lBuffSize = 256
strBuffer = String(lBuffSize, vbNullChar)

'Get current short date format
lRetVal = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strBuffer, lBuffSize)

If lRetVal > 0 Then
strShortDateFormat = Left(strBuffer, lRetVal - 1)
Else
Exit Function
End If

'If current short date format is different from your format, change it.
'Note: MMM should be used in capital for month,small m are for minutes
If UCase(strShortDateFormat) <> UCase(strFormat) Then
lRetVal = SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strFormat)
End If

If lRetVal > 0 Then mdlChangeSystemDateFormat = True
End Function

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus