'#Language "WWB-COM" ' Generate numbered tags in groups ' © Harport Consulting 2022 Option Explicit Const N_GroupSize = 100 Const N_Groups = 90 Const T_GroupMask = "{0} - {1}" Const T_TagMask = "NFP#{0}" Const T_TagFormat = "000#" ' under 10,000 tags Dim m__Document As Document Sub Main Dim m_TagGroup As MapMarkerGroup Dim i_GroupBase As Long Dim i_Tag As Long If Not (ActiveDocument Is Nothing) Then If MsgBox("Map Index task pane closed?", vbQuestion + vbYesNo) = vbYes Then Set m__Document = ActiveDocument Set m_TagGroup = Nothing i_GroupBase = 0 i_Tag = 1 While True If i_Tag > N_GroupSize Then i_Tag = 1 Set m_TagGroup = Nothing i_GroupBase = i_GroupBase + N_GroupSize If i_GroupBase >= N_Groups * N_GroupSize Then Exit While End If If m_TagGroup Is Nothing Then TagGroupAdd(StrFormat(T_GroupMask, TagName(i_GroupBase + 1), _ TagName(i_GroupBase + N_GroupSize)), m_TagGroup) End If TagGroupAddTag(m_TagGroup, TagName(i_GroupBase + i_Tag)) i_Tag = i_Tag + 1 Wend End If End If End Sub Function TagName(ByVal i_Tag As Long) As String TagName = StrFormat(T_TagMask, Format(i_Tag, T_TagFormat)) End Function Function TagGroupAdd(ByVal s_TagGroupName As String, ByRef m_TagGroup As MapMarkerGroup) As Boolean ' Add a new tag group ' Return true if successful, false if not added Dim m_Group As MapMarkerGroup TagGroupAdd = False Set m_TagGroup = Nothing s_TagGroupName = Trim(s_TagGroupName) If Len(s_TagGroupName) = 0 Then Exit Function For Each m_Group In m__Document.MapMarkerGroups If UCase(Trim(m_Group.Name)) = UCase(s_TagGroupName) Then Set m_TagGroup = m_Group Exit For End If Next If m_TagGroup Is Nothing Then ' create Set m_TagGroup = m__Document.MapMarkerGroups.AddTextLabelMarkerGroup(s_TagGroupName) m_TagGroup.MutuallyExclusive = False ' Cannot set sorting through API TagGroupAdd = True Else If m_TagGroup.Type = mmMapMarkerGroupTypeTextLabel Then ' right type TagGroupAdd = True Else Set m_TagGroup = Nothing End If End If End Function Function TagGroupAddTag(ByVal m_TagGroup As MapMarkerGroup, ByVal s_Tag As String) As MapMarker ' Add a tag to the tag group Dim m_Tag As MapMarker On Error Resume Next For Each m_Tag In m_TagGroup If m_Tag.Label = s_Tag Then Set TagGroupAddTag = m_Tag Exit For End If Next If TagGroupAddTag Is Nothing Then Set m_Tag = m_TagGroup.AddTextLabelMarker(s_Tag) Set TagGroupAddTag = m_Tag End If If Err.Number <> 0 Then Set TagGroupAddTag = Nothing Err.Clear End If On Error GoTo 0 End Function Function StrFormat(ByVal s_Format As String, Optional ByVal s_Arg00 As String = "", Optional ByVal s_Arg01 As String = "", Optional ByVal s_Arg02 As String = "", _ Optional ByVal s_Arg03 As String = "", Optional ByVal s_Arg04 As String = "", Optional ByVal s_Arg05 As String = "", Optional ByVal s_Arg06 As String = "", _ Optional ByVal s_Arg07 As String = "", Optional ByVal s_Arg08 As String = "", Optional ByVal s_Arg09 As String = "", Optional ByVal s_Arg10 As String = "", _ Optional ByVal s_Arg11 As String = "", Optional ByVal s_Arg12 As String = "", Optional ByVal s_Arg13 As String = "", Optional ByVal s_Arg14 As String = "", _ Optional ByVal s_Arg15 As String = "", Optional ByVal s_Arg16 As String = "", Optional ByVal s_Arg17 As String = "", Optional ByVal s_Arg18 As String = "") As String ' String formatting: replace {0}..{9} if provided ' Also support \n for newline s_Format = Replace(s_Format, "\n", vbCrLf) If Not IsMissing(s_Arg00) Then s_Format = Replace(s_Format, "{0}", s_Arg00) If Not IsMissing(s_Arg01) Then s_Format = Replace(s_Format, "{1}", s_Arg01) If Not IsMissing(s_Arg02) Then s_Format = Replace(s_Format, "{2}", s_Arg02) If Not IsMissing(s_Arg03) Then s_Format = Replace(s_Format, "{3}", s_Arg03) If Not IsMissing(s_Arg04) Then s_Format = Replace(s_Format, "{4}", s_Arg04) If Not IsMissing(s_Arg05) Then s_Format = Replace(s_Format, "{5}", s_Arg05) If Not IsMissing(s_Arg06) Then s_Format = Replace(s_Format, "{6}", s_Arg06) If Not IsMissing(s_Arg07) Then s_Format = Replace(s_Format, "{7}", s_Arg07) If Not IsMissing(s_Arg08) Then s_Format = Replace(s_Format, "{8}", s_Arg08) If Not IsMissing(s_Arg09) Then s_Format = Replace(s_Format, "{9}", s_Arg09) If Not IsMissing(s_Arg10) Then s_Format = Replace(s_Format, "{10}", s_Arg10) If Not IsMissing(s_Arg11) Then s_Format = Replace(s_Format, "{11}", s_Arg11) If Not IsMissing(s_Arg12) Then s_Format = Replace(s_Format, "{12}", s_Arg12) If Not IsMissing(s_Arg13) Then s_Format = Replace(s_Format, "{13}", s_Arg13) If Not IsMissing(s_Arg14) Then s_Format = Replace(s_Format, "{14}", s_Arg14) If Not IsMissing(s_Arg15) Then s_Format = Replace(s_Format, "{15}", s_Arg15) If Not IsMissing(s_Arg16) Then s_Format = Replace(s_Format, "{16}", s_Arg16) If Not IsMissing(s_Arg17) Then s_Format = Replace(s_Format, "{17}", s_Arg17) If Not IsMissing(s_Arg18) Then s_Format = Replace(s_Format, "{18}", s_Arg18) StrFormat = s_Format End Function