Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adjust Windows Date/Time from Excel VBA
Hi,
Is there any method to adjust Windows Date/Time from Excel VBA? Regards, Chris |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adjust Windows Date/Time from Excel VBA
Chris,
I would imagine the SetSystemTime API. However, I would hope the user has OK'd this change before you make the call. <From API-Guide: http://www.allapi.net/ The SetSystemTime function sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC). Private Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long Private Sub Form_Load() Dim lpSystemTime As SYSTEMTIME lpSystemTime.wYear = 2000 lpSystemTime.wMonth = 1 'Note: The wDayOfWeek member of the SYSTEMTIME structure is ignored. lpSystemTime.wDayOfWeek = -1 lpSystemTime.wDay = 24 lpSystemTime.wHour = 23 lpSystemTime.wMinute = 26 lpSystemTime.wSecond = 0 lpSystemTime.wMilliseconds = 0 'set the new time SetSystemTime lpSystemTime End Sub </From API-Guide: http://www.allapi.net/ NickHK "Chris L" wrote in message ... Hi, Is there any method to adjust Windows Date/Time from Excel VBA? Regards, Chris |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adjust Windows Date/Time from Excel VBA
You can try using this:
Sub setTime() strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(SystemTime)} !\\" & _ strComputer & "\root\cimv2") Set dt = CreateObject("WbemScripting.SWbemDateTime") dt.Year = 2007 dt.Month = 4 dt.Day = 12 dt.Hours = 21 dt.Minutes = 10 dt.Seconds = 30 dt.Microseconds = 0 dt.UTC = -480 'GMT - 8 h Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem In colOperatingSystems objOperatingSystem.SetDateTime dt.Value Next End Sub You need administrator privileges to run this -- urkec "Chris L" wrote: Hi, Is there any method to adjust Windows Date/Time from Excel VBA? Regards, Chris |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Converting text format of time/date into Excel time/date for subtr | Excel Worksheet Functions | |||
formual to determine if date falls on weekend, adjust date to Mond | Excel Discussion (Misc queries) | |||
Excel, How do I get rows to adjust to cronological order of date | Excel Discussion (Misc queries) | |||
Adjust Time | Excel Programming | |||
Spinner box in Excel to adjust date | Excel Worksheet Functions |