您知道如何找出系統在您的計算機中設置的時區嗎? 在這里,我將向您展示一種簡單的方法來在Excel中實現它。
獲取當前時區并在具有用戶定義功能的單元格中顯示
以下用戶定義的函數將幫助您直接在Excel中的所需單元格中顯示系統的當前時區。 請做如下。
1。 按 其他 + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。
2。 在里面 Microsoft Visual Basic for Applications 窗口中,單擊 插頁 > 模塊。 然后將VBA代碼復制到模塊窗口中。
VBA代碼:在Excel中獲取當前時區
Function GetTimeZoneAtPresent() As String
‘Updated by Extendoffice 20180814
Dim xObjIs, xObjI
On Error GoTo ER
Set xObjIs = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * From Win32_TimeZone")
If xObjIs.Count = 1 Then
For Each xObjI In xObjIs
If Len(xObjI.Caption) > 1 Then
GetTimeZoneAtPresent = xObjI.Caption
Exit Function
Else
GetTimeZoneAtPresent = "Null"
Exit Function
End If
Next
End If
ER:
GetTimeZoneAtPresent = "Failed"
End Function
3。 按 其他 + Q 鍵退出 Microsoft Visual Basic for Applications 窗口。
4。 選擇顯示時區所需的單元格,鍵入以下公式: =GetTimeZoneAtPresent() 然后按 輸入 獲取時區細節的關鍵。 查看截圖: