您知道如何找出系統(tǒng)在您的計(jì)算機(jī)中設(shè)置的時(shí)區(qū)嗎? 在這里,我將向您展示一種簡(jiǎn)單的方法來(lái)在Excel中實(shí)現(xiàn)它。
獲取當(dāng)前時(shí)區(qū)并在具有用戶(hù)定義功能的單元格中顯示
以下用戶(hù)定義的函數(shù)將幫助您直接在Excel中的所需單元格中顯示系統(tǒng)的當(dāng)前時(shí)區(qū)。 請(qǐng)做如下。
1。 按 其他 + F11 鍵打開(kāi) Microsoft Visual Basic for Applications 窗口。
2。 在里面 Microsoft Visual Basic for Applications 窗口中,單擊 插頁(yè) > 模塊。 然后將VBA代碼復(fù)制到模塊窗口中。
VBA代碼:在Excel中獲取當(dāng)前時(shí)區(qū)
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。 選擇顯示時(shí)區(qū)所需的單元格,鍵入以下公式: =GetTimeZoneAtPresent() 然后按 輸入 獲取時(shí)區(qū)細(xì)節(jié)的關(guān)鍵。 查看截圖: