You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Data Editing forum

How do I change Label Expression with VBA m...   Chirag Shukla May 22, 2003
Re: How do I change Label Expression with V...   Olivier Damanet May 22, 2003
Re: How do I change Label Expression with V...   Chirag Shukla May 23, 2003
Re: How do I change Label Expression with V...   Kristen MacDougall Oct 18, 2004
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject How do I change Label Expression with VBA macro? 
Author Chirag Shukla 
Date May 22, 2003 
Message I want to change the label expression of a feature class so as to display a different value on the map when a macro is run. e.g. Currently, I show temperature values from [temp] field using the expression [maxtemp] & "/" & [mintemp]. And now I want to invoke a macro so that values for rain is shown from [rain] field. I want to automate things...

I know I can have different layers for different values that I need to access, and then just add/remove layers. But I dont want to do that.

I would appreciate if somebody could write me few lines of code to indicate ways to set the label expression property using VBA.

Thanks, in advance.

Chirag.
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How do I change Label Expression with VBA macro? 
Author Olivier Damanet 
Date May 22, 2003 
Message See below 
 
Sub SetLabelExpression()
    ' get first layer in map
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pFLayer As IFeatureLayer
    If Not TypeOf pMxDoc.FocusMap.Layer(0) Is IGeoFeatureLayer Then
        Exit Sub
    End If
    
'+++ setup LabelEngineProperties for the FeatureLayer
    ' get the AnnotateLayerPropertiesCollection for the FeatureLayer
    Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection
    Set pAnnoLayerPropsColl = pFLayer.AnnotationProperties
    pAnnoLayerPropsColl.Clear
    
    ' create a new LabelEngineLayerProperties object
    Dim aLELayerProps As ILabelEngineLayerProperties
    Set aLELayerProps = New LabelEngineLayerProperties
    aLELayerProps.Expression = "[Field1] & "" "" & [Field2]"
    
    ' assign it to the layer's AnnotateLayerPropertiesCollection
    pAnnoLayerPropsColl.Add aLELayerProps

'+++ refresh the map
    pMxDoc.ActiveView.Refresh
End Sub
 
  Olivier. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How do I change Label Expression with VBA macro? 
Author Chirag Shukla 
Date May 23, 2003 
Message First it did not work but then I changed
Dim pFLayer As IFeatureLayer to
Dim pFLayer As IGeoFeatureLayer

Later on, I commented:
' If Not TypeOf pMxDoc.FocusMap.Layer(0) Is IGeoFeatureLayer Then
' Exit Sub
' End If

and instead of that just wrote:
Set pFLayer = pMxDoc.FocusMap.Layer(0)

and bingo! Things worked. Thanks very much Olivier. I appreciate your quick response and help. 
 
Changes:
'Dim pFLayer As IFeatureLayer

Dim pFLayer As IGeoFeatureLayer

'    If Not TypeOf pMxDoc.FocusMap.Layer(0) Is IGeoFeatureLayer Then
'        Exit Sub
'    End If

Set pFLayer = pMxDoc.FocusMap.Layer(0)
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How do I change Label Expression with VBA macro? 
Author Kristen MacDougall 
Date Oct 18, 2004 
Message Hello all;

Does anyone know how to make this code work for all layers in the Table of Contents, rather than for just the first layer?

I am inexperienced with VBA and don't know how to do this.

Thanks,

Kristen