Would be quite a welcome addition to DNN wouldn't it?
Well, here's some code I created that solves this but be mindful that this searches by the Name of the Page ... so if you have a root page called Test and put a page who has Test as it's parent and name Level 2, when you search for this subpage it's named ...Level 2 and not Level 2. Just like Pages look in the Pages listbox.
Public Function GetTabID(ByVal PageName As String) As Integer
' Locals
Dim objTab As DotNetNuke.Entities.Tabs.TabInfo
Dim arrPortalTabs As ArrayList
' Get the Tabs
arrPortalTabs = GetPortalTabs(PortalSettings.DesktopTabs, False, True, False, True)
' Find the TabID based on the Name
For Each objTab In arrPortalTabs
If objTab.TabName = PageName Then
Return objTab.TabID
End If
Next
' Return
Return 0
End Function