Advertisement
xlujiax

Error

Jan 29th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Public Sub AbrirLibros()
  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.     Dim chrt As ChartObject
  14.     Dim nombreimg As String
  15.     Dim Filename As String
  16.    
  17.  
  18.  
  19.     strRutaInicial = "D:\Check_List_Hold_Point"
  20.  
  21.  
  22.     Set fso = CreateObject("Scripting.FileSystemObject")
  23.  
  24.     Set fCarpeta = fso.GetFolder(strRutaInicial)
  25.  
  26.  
  27.     For Each tmpFichero In fCarpeta.Files
  28.  
  29.     If LCase(Mid(tmpFichero.Name, InStr(tmpFichero.Name, ".") + 1)) = "xlsx" Then
  30.         Workbooks.Open tmpFichero.Path
  31.        
  32.         Application.ScreenUpdating = False
  33.         For Each img In ActiveSheet.Shapes
  34.         Charts.Add
  35.         ActiveChart.ChartArea.Clear
  36.        
  37.         Set chrt = ActiveSheet.ChartObjects(1)
  38.             nombreimg = img.Name
  39.             With img
  40.             chrt.Width = .Width
  41.             chrt.Height = .Height
  42.             .Copy
  43.             End With
  44.             chrt.Chart.Export Filename = "D:\Graficos\" & nombreimg & ".gif"
  45.         chrt.Delete
  46.         Next img
  47.         Application.ScreenUpdating = True
  48.        
  49.         ActiveWorkbook.Close savechanges:=False
  50.     End If
  51.  
  52.     Next tmpFichero
  53.  
  54.  
  55.     Recursivo strRutaInicial
  56.  
  57. End Sub
  58.  
  59.  
  60. Private Sub Recursivo(ByVal RutaInicial As String)
  61.  
  62.     Dim fso As Object, fCarpeta As Object, tmpCarpeta As Object
  63.  
  64.     Dim Fichero As Object, tmpFichero As Object
  65.    
  66.     Dim img As Shape
  67.     Dim chrt As ChartObject
  68.     Dim nombreimg As String
  69.     Dim Filename As String
  70.  
  71.  
  72.     Set fso = CreateObject("Scripting.FileSystemObject")
  73.  
  74.     Set fCarpeta = fso.GetFolder(RutaInicial)
  75.  
  76.  
  77.     For Each tmpCarpeta In fCarpeta.SubFolders
  78.  
  79.         For Each tmpFichero In tmpCarpeta.Files
  80.  
  81.             If LCase(Mid(tmpFichero.Name, InStr(tmpFichero.Name, ".") + 1)) = "xlsx" Then
  82.                 Workbooks.Open tmpFichero.Path
  83.                
  84.                 Application.ScreenUpdating = False
  85.                 For Each img In ActiveSheet.Shapes
  86.                 Charts.Add
  87.                
  88.                
  89.                 ' ActiveChart.Location Where:=xlLocationAsObject, Name:="Hoja1"
  90.                Set chrt = ActiveSheet.ChartObjects(0)
  91.                
  92.                     nombreimg = img.Name
  93.                     With img
  94.                     chrt.Width = .Width
  95.                     chrt.Height = .Height
  96.                     .Copy
  97.                     End With
  98.                     ActiveChart.Paste
  99.                    
  100.                     chrt.Chart.Export Filename = "D:\Graficos\" & nombreimg & ".gif"
  101.                 chrt.Delete
  102.                 Next img
  103.                 Application.ScreenUpdating = True
  104.                
  105.                
  106.                 ActiveWorkbook.Close savechanges:=False
  107.             End If
  108.  
  109.         Next
  110.  
  111.         Recursivo tmpCarpeta.Path
  112.  
  113.     Next tmpCarpeta
  114.  
  115. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement