Advertisement
xlujiax

ImagenesFinal

Jan 31st, 2019
145
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.        
  32.         Application.ScreenUpdating = True
  33.        
  34.         ActiveWorkbook.Close savechanges:=False
  35.     End If
  36.  
  37.     Next tmpFichero
  38.  
  39.  
  40.     Recursivo strRutaInicial
  41.  
  42. End Sub
  43.  
  44.  
  45. Private Sub Recursivo(ByVal RutaInicial As String)
  46.  
  47.     Dim fso As Object, fCarpeta As Object, tmpCarpeta As Object
  48.  
  49.     Dim Fichero As Object, tmpFichero As Object
  50.    
  51.     Dim ruta As String
  52.     Dim hojaActual As Worksheet
  53.     Dim graficoActual As ChartObject
  54.     Dim img As Shape
  55.     Dim strTempName As String
  56.     ' Dim objHolder As ChartObject
  57.    Dim PicWidth As Long, PicHeight As Long
  58.     Dim MyChart As String, MyPicture As String
  59.     Dim intIndex As Integer
  60.    
  61.     Dim intListCount As Integer
  62.     Dim objTemp As Object
  63.     Dim objHolder As ChartObject
  64.     Dim sngWidth As Single
  65.     Dim sngHeight As Single
  66.     Dim shapeType As Integer
  67.    
  68.    
  69.     Set fso = CreateObject("Scripting.FileSystemObject")
  70.  
  71.     Set fCarpeta = fso.GetFolder(RutaInicial)
  72.  
  73.     ruta = "D:\Graficos\"
  74.  
  75.     For Each tmpCarpeta In fCarpeta.SubFolders
  76.  
  77.         For Each tmpFichero In tmpCarpeta.Files
  78.  
  79.             If LCase(Mid(tmpFichero.Name, InStr(tmpFichero.Name, ".") + 1)) = "xlsx" Then
  80.                 Workbooks.Open tmpFichero.Path
  81.                
  82.                 Application.ScreenUpdating = False
  83.                
  84.                 For Each hojaActual In Sheets
  85.                    
  86.                     For intIndex = 1 To hojaActual.Shapes.Count
  87.                          On Error Resume Next
  88.                          
  89.                          Set objTemp = ActiveSheet.Shapes(intIndex)
  90.                          strTempName = ActiveSheet.Shapes(intIndex).Name
  91.                          shapeType = CStr(ActiveSheet.Shapes(intIndex).Type)
  92.                          
  93.                          Set objHolder = ActiveSheet.ChartObjects.Add(100, 200, 400, 200)
  94.                          objHolder.Activate
  95.                          
  96.                          sngWidth = objTemp.Width
  97.                          sngHeight = objTemp.Height
  98.                          
  99.                          With objHolder
  100.                             .Width = sngWidth + 20
  101.                             .Height = sngHeight + 20
  102.                             If shapeType = 6 Then 'Objetos Agrupados
  103.                                objTemp.CopyPicture xlScreen, xlBitmap
  104.                             Else
  105.                                 objTemp.Copy
  106.                             End If
  107.                          End With
  108.                          
  109.                          With objHolder
  110.                             .Chart.Paste
  111.                             With .Chart.Shapes(1)
  112.                                 .Placement = xlMove
  113.                                 .Left = -4
  114.                                 .Top = -4
  115.                             End With
  116.                             .Width = sngWidth + 1
  117.                             .Height = sngHeight + 1
  118.                             .Chart.Export ruta & tmpFichero.Name & hojaActual.Name & "-" & strTempName & ".jpg", "jpg"
  119.                             .Chart.Shapes(1).Delete
  120.                            
  121.                            
  122.                         End With
  123.  
  124.                     Next
  125.                        
  126.  
  127.                 Next
  128.                
  129.                 Application.ScreenUpdating = True
  130.                
  131.                
  132.                 ActiveWorkbook.Close savechanges:=False
  133.             End If
  134.  
  135.         Next
  136.  
  137.         Recursivo tmpCarpeta.Path
  138.  
  139.     Next tmpCarpeta
  140.  
  141. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement