Date format

J

Jos Vens

Hi,

how can I know what the default date and time format is set on the user's
computer. Now I set it to a special format (yy-mm-dd) but the user asks to
let it be like his computer's setting.

Thanks
Jos Vens
 
T

Tom Ogilvy

If you just put a date in an unformatted cell, it should use the default
date

activecell.Value = Date
? activeCell.NumberFormat
m/d/yy
ActiveCell.Offset(1,0).Value = Time
? activeCell.Offset(1,0).Numberformat
h:mm:ss AM/PM
 
J

Jos Vens

Thanks Tom,

but: if i use your code, I get 05-10-29 in my cell (my systemsetting is
jj-MM-dd)
but ?activecell.numberformat gives me "m/d/yyyy", which is not my
systemsetting.

Can you still help me?
Jos
 
B

Bob Phillips

Jens,

Try NumberFormatLocal instead.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
N

Norman Jones

Hi Jens,

Try:
'=================>>
Function SettingVaL(strSetting As String)
Dim strComputer As String
Dim strKeyPath As String
Dim strEntryName As Variant
Dim strValue As String
Dim strLogFile As String
Dim objReg As Object
Dim objFSO As Object
Dim arrValue, byteValue, arrEntryNames, arrValueTypes


Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_USER = &H80000001
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7


strKeyPath = ".DEFAULT\Control Panel\International"
strLogFile = "C:\RegionalSettings.txt"


Set objFSO = CreateObject("Scripting.FileSystemObject")
''Set objLogFile = objFSO.CreateTextFile(strLogFile)
'''objLogFile.Writeline ("This logfile was made on " _
& Date & " at " & Time & "." & VbCrLf )

strComputer = "."

' Connect to the WMI Regisitry-provider
Set objReg = GetObject("winmgmts:{impersonationLevel" _
& "=impersonate}!\\" & strComputer _
& "\root\default:StdRegProv")

objReg.EnumValues HKEY_USERS, strKeyPath, _
arrEntryNames, arrValueTypes
For Each strEntryName In arrEntryNames
'*** This is the only Binary value
If strEntryName = "DefaultBlindDialFlag" Then
objReg.GetBinaryValue HKEY_USERS, strKeyPath, _
strEntryName, arrValue

For Each byteValue In arrValue
If strEntryName = "s" & strSetting Then
SettingVaL = strValue
Exit Function
End If
Next
Else
'*** These are all RegSZ value's
objReg.GetStringValue HKEY_USERS, strKeyPath, _
strEntryName, strValue
If strEntryName = "s" & strSetting Then
SettingVaL = strValue
Exit Function
End If

End If
Next

End Function
'<<=================

'=================>>
Sub GetDateFormat()
Dim ShortDt As String
Dim LongDt As String

ShortDt = SettingVaL("ShortDate")
LongDt = SettingVaL("LongDate")

MsgBox ShortDt & vbNewLine & LongDt
End Sub
'<<=================
 
J

Jos Vens

Thanks Bob,

it is really what I'm looking for

Thanks Norman for your code I may use later maybe,

Greetings
Jos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top