Hi All,I'm trying to copy labeling properties from layer A to layer B using VB-code in an mxd I'm creating.I tried the following code:'Apply labeling properties from 'Layer_A' to 'Layer_B'
[INDENT]Dim IGeoFeatureLayerA, IGeoFeatureLayerB As IGeoFeatureLayer[/INDENT]
'Find layers A and B
[INDENT]Set IGeoFeatureLayerA = GetLayerByName("Layer_A")
Set IGeoFeatureLayerB = GetLayerByName("Layer B")[/INDENT]
'Apply labeling settings from feature layer Layer_A to feature layer Layer_B
[INDENT]Dim pAnnoLayerPropsCollA, pAnnoLayerPropsCollB As IAnnotateLayerPropertiesCollection
Dim pAnnoLayerPropsA As IAnnotateLayerProperties
Set pAnnoLayerPropsCollA = IGeoFeatureLayerA.AnnotationProperties
Set pAnnoLayerPropsCollB = IGeoFeatureLayerB.AnnotationProperties
pAnnoLayerPropsCollA.QueryItem 0, pAnnoLayerPropsA, Nothing, Nothing
pAnnoLayerPropsCollB.Add pAnnoLayerPropsA
IGeoFeatureLayer1.DisplayAnnotation = True[/INDENT]
And the custom function GetLayerByName:Public Function GetLayerByName(strLayerName As String) As IGeoFeatureLayer
'Returns the layer based on the given name. The layer may be in a grouplayer, which itself may also be in a group layer.
'Deeper nesting is not supported and would need adjustment of the code below
Dim pDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Dim pFeatureLayer As IFeatureLayer
Dim i As Integer
Set pDoc = ThisDocument
Set pMap = pDoc.FocusMap
For i = 0 To pMap.LayerCount - 1
Set pLayer = pMap.Layer(i)
If TypeOf pLayer Is IGeoFeatureLayer Then 'Layer is a geofeature layer.
Set pFeatureLayer = pLayer
If pFeatureLayer.Name = strLayerName Then 'Layer has the right name.
Set GetLayerByName = pFeatureLayer
Exit Function
End If
ElseIf TypeOf pLayer Is IGroupLayer Then 'Layer is a grouplayer. Check its contents.
Dim pCompLayer As ICompositeLayer
Set pCompLayer = pLayer
Dim j As Integer
For j = 0 To pCompLayer.Count - 1
If TypeOf pCompLayer.Layer(j) Is IGeoFeatureLayer Then 'Sublayer is a geofeature layer.
Set pFeatureLayer = pCompLayer.Layer(j)
If pFeatureLayer.Name = strLayerName Then 'Sublayer has the right name.
Set GetLayerByName = pFeatureLayer
Exit Function
End If
ElseIf TypeOf pCompLayer.Layer(j) Is IGroupLayer Then 'Sublayer is a grouplayer. Check its contents.
Dim pCompLayer2 As ICompositeLayer
Set pCompLayer2 = pCompLayer.Layer(j)
Dim k As Integer
For k = 0 To pCompLayer2.Count - 1
If TypeOf pCompLayer2.Layer(k) Is IGeoFeatureLayer Then 'Subsublayer is a geofeature layer.
Set pFeatureLayer = pCompLayer2.Layer(k)
If pFeatureLayer.Name = strLayerName Then 'Subsublayer has the right name.
Set GetLayerByName = pFeatureLayer
Exit Function
End If
End If
Next k
End If
Next j
End If
Next i
End Function
Now when I run this code, I get a Compile error: ByRef argument type mismatch. I get it on this line, specifically on the variable pAnnoLayerPropsA:pAnnoLayerPropsCollA.QueryItem 0, pAnnoLayerPropsA, Nothing, Nothing
I don't understand. I though the second argument for IAnnotateLayerPropertiesCollection.QueryItem should be an IAnnotateLayerProperties object. So, two questions:
- Why do I get the error mentioned above? How can I prevent it from occurring?
- Is the approach I'm taking for the problem (getting the labeling properties from Layer A to Layer B) the best way to go? Do you have suggestions for improvements. I have experience in programming in VBA for MS Access and MS Excel, but I'm new to programming in ArcGis.
Thanks in advance for any help!
Best regards,
Martijn Senden.