Dim pElement As IElement Set pElement = pGraphicsContainer.Next Do While Not pElement Is Nothing If TypeOf pElement Is IMapSurroundFrame Then Dim pMapSurroundFrame As IMapSurroundFrame Set pMapSurroundFrame = pElement Dim pMapSurround As IMapSurround Set pMapSurround = pMapSurroundFrame.MapSurround If TypeOf pMapSurround Is IScaleBar Then Dim pEnvelope As IEnvelope Set pEnvelope = New Envelope Dim pXMin As Double pXMin = pElement.Geometry.Envelope.XMin Dim pYMin As Double pYMin = pElement.Geometry.Envelope.YMin Dim pXMax As Double pXMax = pXMin + 2.5 Dim pYMax As Double pYMax = pYMin + 0.3 pEnvelope.PutCoords pXMin, pYMin, pXMax, pYMax pElement.Geometry.QueryEnvelope pEnvelope ' MsgBox "Xmin = " & Round(pXMin, 2) & " XMax = " & Round(pXMax, 2) & " YMin = " & Round(pYMin, 2) & " YMax = " & Round(pYMax, 2) ' MsgBox pEnvelope.Width & " " & pEnvelope.Height Dim pScaleBar As IScaleBar Set pScaleBar = pMapSurround Dim dblscale As Double Dim intdiv As Integer dblscale = pMapSurroundFrame.MapFrame.MapScale / 1000000 Select Case dblscale Case 0 To 4 intdiv = 50 Case 4.001 To 6 intdiv = 100 'Case 5 To 7 ' intdiv = 150 Case 6.0001 To 8.6 intdiv = 200 Case 8.60001 To 14 intdiv = 250 Case 14.0001 To 20 intdiv = 500 Case Else ' Other values. intdiv = 1000 End Select With pScaleBar ' ' .Division = Round((pMapSurroundFrame.MapFrame.MapScale / 10000000), 10) * 1000 .Division = intdiv .Divisions = 2 .Subdivisions = 2 .DivisionsBeforeZero = 1 .LabelFrequency = esriScaleBarDivisions .LabelPosition = esriAbove .Units = esriKilometers .UnitLabel = "Kilometers" .ResizeHint = esriScaleBarFixed End With End If End If Set pElement = pGraphicsContainer.Next Loop