Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Adjust Windows Date/Time from Excel VBA

Hi,

Is there any method to adjust Windows Date/Time from Excel VBA?

Regards,
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting text format of time/date into Excel time/date for subtr YY san.[_2_] Excel Worksheet Functions 6 February 25th 10 08:27 AM
formual to determine if date falls on weekend, adjust date to Mond Bradley Excel Discussion (Misc queries) 4 November 21st 08 06:19 PM
Excel, How do I get rows to adjust to cronological order of date Jay.... Needing help Excel Discussion (Misc queries) 7 July 7th 06 08:21 PM
Adjust Time Martin Wheeler Excel Programming 2 February 28th 06 01:32 AM
Spinner box in Excel to adjust date Mrebisz3154 Excel Worksheet Functions 4 October 28th 05 11:32 PM


All times are GMT +1. The time now is 05:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"