Thank you again Ken,
I made some changes you mentioned and add some Public sub to setup the path to save the gif files and it works perfectly.
Now, another thing is that how can I do the same thing for spatial image files?
Any help?
Thank you
Private Sub ExportToGIF()
Dim pActiveView As IActiveView
Dim pRaster As IRaster
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Set pActiveView = pMxDoc.activeView
Dim pExtent As IEnvelope
Set pExtent = pActiveView.extent
Dim pEnumLayer As IEnumLayer
Set pEnumLayer = pMap.Layers
pEnumLayer.Reset
Dim pLayer As ILayer
Set pLayer = pEnumLayer.Next
Do While Not (pLayer Is Nothing)
pLayer.Visible = False
Set pLayer = pEnumLayer.Next
Loop
pEnumLayer.Reset
Set pLayer = pEnumLayer.Next
Do While Not (pLayer Is Nothing)
If TypeOf pLayer Is IFeatureLayer Then
pLayer.Visible = True
pActiveView.extent = pLayer.AreaOfInterest
pActiveView.Refresh
ExportLayout "GIF", "C:\Users\Desktop\" & pLayer.Name & ".gif", 175
'System.Windows.Forms.MessageBox.Show (pLayer.Name)
pLayer.Visible = False
End If
Set pLayer = pEnumLayer.Next
Loop
pEnumLayer.Reset
Set pLayer = pEnumLayer.Next
Do While Not (pLayer Is Nothing)
pLayer.Visible = True
Set pLayer = pEnumLayer.Next
Loop
Set pExtent = pActiveView.extent '= pExtent
pActiveView.Refresh
End Sub
Public Sub ExportLayout(Format As String, FileName As String, dpi As Integer)
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pLayout As IActiveView
Set pLayout = pMxDoc.PageLayout
Dim rectOut As tagRECT
rectOut = pLayout.ExportFrame
Dim pEnv As IEnvelope
Set pEnv = New Envelope
pEnv.PutCoords rectOut.Left, rectOut.Top, rectOut.Right, rectOut.bottom
Dim pExporter As IExporter
If Format = "GIF" Then
Set pExporter = New JpegExporter
Else
Set pExporter = New PDFExporter
End If
pExporter.ExportFileName = FileName
pExporter.PixelBounds = pEnv
pExporter.Resolution = dpi
'Recalc the export frame to handle the increased number of pixels
Set pEnv = pExporter.PixelBounds
Dim xMin As Double, yMin As Double
Dim xMax As Double, yMax As Double
pEnv.QueryCoords xMin, yMin, xMax, yMax
rectOut.Left = xMin
rectOut.Top = yMin
rectOut.Right = xMax
rectOut.bottom = yMax
'Do the export
Dim hDC As Long
hDC = pExporter.StartExporting
pLayout.Output hDC, dpi, rectOut, Nothing, Nothing
pExporter.FinishExporting
'MsgBox "Export complete!", vbInformation
End Sub