如何在excel中找到用户的时区偏移量

时间:2009-02-10 12:04:35

标签: excel-vba vba excel

我正在使用excel宏来生成RSS提要。用户的时区偏移需要在RSS源的字段中。如何在excel宏函数中以编程方式执行此操作?

1 个答案:

答案 0 :(得分:0)

将以下代码粘贴到Excel中的模块中:

Private Declare Function GetTimeZoneInformationAny Lib "kernel32" Alias _
  "GetTimeZoneInformation" (buffer As Any) As Long

Function GetTimeZone() As Single
  Dim retval As Long
  Dim buffer(0 To 42) As Long

  Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
  Const TIME_ZONE_ID_UNKNOWN = 0
  Const TIME_ZONE_ID_STANDARD = 1
  Const TIME_ZONE_ID_DAYLIGHT = 2

  retval = GetTimeZoneInformationAny(buffer(0))

  Select Case retval
    Case TIME_ZONE_ID_INVALID
      GetTimeZone = 0
    Case TIME_ZONE_ID_STANDARD, TIME_ZONE_ID_UNKNOWN
      GetTimeZone = (buffer(0) + buffer(21)) / -60
    Case TIME_ZONE_ID_DAYLIGHT
      GetTimeZone = (buffer(0) + buffer(42)) / -60
    Case Else
      GetTimeZone = 0
  End Select

End Function

(来自http://binaryworld.net/Main/CodeDetail.aspx?CodeId=152