How to change regional setting short date as dd/mm/yyyy through vba code
-
In India we are using the date format as dd/mm/yyyy (United Kingdom). By default short date is mm/dd/yyyy (United State). How to change the short date format though VBA code in ms excel. Kindly help me. Dhandapani
-
Answer:
Dhandapani, Insert a new module and paste in this code: Private Const LOCALE_SSHORTDATE = &H1F Private Const WM_SETTINGCHANGE = &H1A Private Const HWND_BROADCAST = &HFFFF& Private Declare Function SetLocaleInfo Lib "kernel32" Alias _ "SetLocaleInfoA" ( _ ByVal Locale As Long, _ ByVal LCType As Long, _ ByVal lpLCData As String) As Boolean Private Declare Function PostMessage Lib "user32" Alias _ "PostMessageA" ( _ ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Private Declare Function GetSystemDefaultLCID Lib "kernel32" _ () As Long Sub chgDate() Dim dwLCID As Long Dim myDate As String dwLCID = GetSystemDefaultLCID() If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "dd/MM/yyyy") _ = False Then MsgBox "Failed" Exit Sub End If PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0 End Sub '---------- change the "dd/MM/yyyy" to the format you want. the code was tested and worked for me.
Miningco.com Visit the source
Related Q & A:
- How to change the date format yyyy/mm/dd to dd/mm/yyyy in below code?Best solution by scn.sap.com
- How do I change the setting of my monitor?Best solution by Yahoo! Answers
- How to change the flight to the earlier date?Best solution by Yahoo! Answers
- How do I change email setting on my scanner?Best solution by Yahoo! Answers
- How to change printer setting?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.