PC Review


Reply
Thread Tools Rate Thread

Adjust Windows Date/Time from Excel VBA

 
 
=?Utf-8?B?Q2hyaXMgTA==?=
Guest
Posts: n/a
 
      12th Apr 2007
Hi,

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

Regards,
Chris
 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      12th Apr 2007
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" <(E-Mail Removed)> wrote in message
news:2F72B3DA-1256-46DB-851C-(E-Mail Removed)...
> Hi,
>
> Is there any method to adjust Windows Date/Time from Excel VBA?
>
> Regards,
> Chris



 
Reply With Quote
 
=?Utf-8?B?dXJrZWM=?=
Guest
Posts: n/a
 
      12th Apr 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjust Date if Start time -> Stop time is overnight Renraf Microsoft Access Form Coding 6 23rd Sep 2009 06:49 PM
Adjust Date/Time news Windows XP Embedded 4 1st Jun 2005 04:32 PM
Cannot adjust Date/Time in XP Pro =?Utf-8?B?bWlzc2luZ21pbGVoaWdo?= Windows XP Customization 2 3rd Oct 2004 03:47 PM
adjust date/time adjust date/time Windows XP Accessibility 0 26th Jul 2004 03:19 PM
ADJUST TIME AND DATE MANU MEHTA Windows XP General 3 6th Apr 2004 02:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:12 AM.