Advertisement
xlujiax

DescargarImagenesFinal

Feb 4th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Public Sub AbrirLibrosv3()
  4.  
  5.     Dim img As Shape
  6.  
  7.     Dim fso As Object, fCarpeta As Object, tmpCarpeta As Object
  8.  
  9.     Dim Fichero As Object, tmpFichero As Object
  10.  
  11.     Dim strRutaInicial As String
  12.  
  13.    
  14.    
  15.     strRutaInicial = "D:\Check_List_Hold_Point"
  16.  
  17.  
  18.     Set fso = CreateObject("Scripting.FileSystemObject")
  19.  
  20.     Set fCarpeta = fso.GetFolder(strRutaInicial)
  21.  
  22.    
  23.     For Each tmpFichero In fCarpeta.Files
  24.  
  25.     If LCase(Mid(tmpFichero.Name, InStr(tmpFichero.Name, ".") + 1)) = "xlsx" Then
  26.         Workbooks.Open tmpFichero.path
  27.        
  28.         Application.ScreenUpdating = False
  29.  
  30.        
  31.         Application.ScreenUpdating = True
  32.        
  33.         ActiveWorkbook.Close savechanges:=False
  34.     End If
  35.  
  36.     Next tmpFichero
  37.  
  38.  
  39.     Recursivo strRutaInicial
  40.  
  41. End Sub
  42.  
  43.  
  44. Private Sub Recursivo(ByVal RutaInicial As String)
  45.  
  46.     Dim fso As Object, fCarpeta As Object, tmpCarpeta As Object
  47.  
  48.     Dim Fichero As Object, tmpFichero As Object
  49.    
  50.     Dim ruta As String
  51.     Dim hojaActual As Worksheet
  52.     Dim strTempName As String
  53.    
  54.     Dim PicWidth As Long, PicHeight As Long
  55.     Dim intIndex As Integer
  56.        
  57.     Dim objTemp As Object
  58.     Dim objHolder As ChartObject
  59.     Dim sngWidth As Single
  60.     Dim sngHeight As Single
  61.     Dim shapeType As Integer
  62.     Dim path As String
  63.     Dim directory As String
  64.    
  65.    
  66.  
  67.     Set fso = CreateObject("Scripting.FileSystemObject")
  68.  
  69.     Set fCarpeta = fso.GetFolder(RutaInicial)
  70.    
  71.     directory = "D:\Graficos\"
  72.     path = directory & Right(fCarpeta, Len(fCarpeta) - 3)
  73.     If Len(Dir(path, vbDirectory)) = 0 Then
  74.         MkDir path
  75.     End If
  76.  
  77.  
  78.     For Each tmpCarpeta In fCarpeta.SubFolders
  79.         Debug.Print tmpCarpeta
  80.         path = directory & Right(tmpCarpeta, Len(tmpCarpeta) - 3)
  81.         If Len(Dir(path, vbDirectory)) = 0 Then
  82.             MkDir path
  83.         End If
  84.         For Each tmpFichero In tmpCarpeta.Files
  85.             If (Left(tmpFichero.Name, 1) = "~") Then  'Valida documentos ocultos
  86.                GoTo Break1
  87.             End If
  88.        
  89.             Debug.Print tmpFichero
  90.             path = directory & Right(tmpFichero, Len(tmpFichero) - 3)
  91.             If Len(Dir(path, vbDirectory)) = 0 Then
  92.                 MkDir path
  93.                 Debug.Print path
  94.             End If
  95.            
  96.             If LCase(Mid(tmpFichero.Name, InStr(tmpFichero.Name, ".") + 1)) = "xlsx" Or LCase(Mid(tmpFichero.Name, InStr(tmpFichero.Name, ".") + 1)) = ".xlsx" Then
  97.                 Application.DisplayAlerts = False
  98.                 Workbooks.Open tmpFichero.path
  99.                
  100.                 Application.ScreenUpdating = False
  101.                
  102.                
  103.                 For Each hojaActual In Sheets
  104.                    
  105.                     For intIndex = 1 To hojaActual.Shapes.Count
  106.                          On Error Resume Next
  107.                          
  108.                          Set objTemp = hojaActual.Shapes(intIndex)
  109.                          strTempName = hojaActual.Shapes(intIndex).Name
  110.                          shapeType = CStr(hojaActual.Shapes(intIndex).Type)
  111.                          
  112.                          Set objHolder = hojaActual.ChartObjects.Add(100, 200, 400, 200)
  113.                          objHolder.Activate
  114.                          
  115.                          sngWidth = objTemp.Width
  116.                          sngHeight = objTemp.Height
  117.                          
  118.                          If intIndex = 20 Then
  119.                              strTempName = hojaActual.Shapes(intIndex).Name
  120.                          End If
  121.                                                  
  122.                          With objHolder
  123.                             .Width = sngWidth + 20
  124.                             .Height = sngHeight + 20
  125.                             If shapeType = 6 Then 'Objetos Agrupados
  126.                                objTemp.CopyPicture xlScreen, xlBitmap
  127.                             Else
  128.                                 objTemp.Copy
  129.                             End If
  130.                          End With
  131.                          
  132.                          With objHolder
  133.                             .Chart.Paste
  134.                             With .Chart.Shapes(1)
  135.                                 .Placement = xlMove
  136.                                 .Left = -4
  137.                                 .Top = -4
  138.                             End With
  139.                             .Width = sngWidth + 1
  140.                             .Height = sngHeight + 1
  141.                              If ((.Height > 40) And ((shapeType = 6) Or (shapeType = 13))) Then
  142.                                 path = path & "\"
  143.                                 .Chart.Export path & strTempName & ".jpg", "jpg"
  144.                              End If
  145.                             .Chart.Shapes(1).Delete
  146.                          End With
  147.                     Next
  148.                    
  149.                 Next
  150.                
  151.                 Application.ScreenUpdating = True
  152.                
  153.                 ActiveWorkbook.Close savechanges:=False
  154.                
  155.                 Application.DisplayAlerts = True
  156.             End If
  157. Break1:
  158.  
  159.         Next
  160.  
  161.         Recursivo tmpCarpeta.path
  162.  
  163.     Next
  164.  
  165. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement