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