costalat

VBA Macro - Read from excel cells

Sep 7th, 2011
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub Workbook_Open()
  2. Dim tamanho As Variant
  3. Dim c As Variant
  4.    Dim ot      As Range
  5.    Dim d_ot As Range
  6.    Dim i_ot      As Range
  7.    Dim m      As Range
  8.    Dim ent      As Range
  9.    Dim inc      As Range
  10.    Dim falta      As Range
  11.    Dim file   As Variant
  12.    Dim subf As Variant
  13.    Dim f
  14.    Dim sf
  15.    Dim ext
  16.    'Limpar área de trabalho
  17.     Range("C10:I550").Clear
  18.    Range("C10:I550").Select
  19.     Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  20.     Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  21.     Selection.Borders(xlEdgeLeft).LineStyle = xlNone
  22.     Selection.Borders(xlEdgeTop).LineStyle = xlNone
  23.     Selection.Borders(xlEdgeBottom).LineStyle = xlNone
  24.     Selection.Borders(xlEdgeRight).LineStyle = xlNone
  25.     Selection.Borders(xlInsideVertical).LineStyle = xlNone
  26.     Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  27.    
  28.    Const folder = "\\Host\EM_TRATAMENTO"
  29.    'Const folder = "F:\RQ\"
  30.    Range("C10").Select
  31.     Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
  32.     Selection.ClearContents
  33.     Selection.NumberFormat = "General"
  34.     Range("C10").Select
  35.     c = 10
  36.     With CreateObject("Scripting.FileSystemObject")
  37.    'OT
  38.       Set ot = ActiveSheet.Cells(10, 3)
  39.        Set d_ot = ActiveSheet.Cells(10, 4)
  40.        Set i_ot = ActiveSheet.Cells(10, 5)
  41.        Set m = ActiveSheet.Cells(10, 6)
  42.        Set ent = ActiveSheet.Cells(10, 7)
  43.        Set inc = ActiveSheet.Cells(10, 8)
  44.        Set falta = ActiveSheet.Cells(10, 9)
  45.        
  46.          For Each subf In .GetFolder(folder).SubFolders
  47.             For Each file In .GetFolder(subf).Files
  48.              If LCase(Left(.GetExtensionName(file.Name), 3)) = "xls" Then
  49.                If Right(.GetBaseName(file), 3) = "REQ" Then
  50.                   ot.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$A$6"
  51.                   ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=file.ParentFolder & "\" & file.Name
  52.                   Set ot = ot.Offset(1)
  53.                   d_ot.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$B$9"
  54.                   Set d_ot = d_ot.Offset(1)
  55.                   i_ot.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$B$10"
  56.                   Set i_ot = i_ot.Offset(1)
  57.                   m.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$B$6"
  58.                   Set m = m.Offset(1)
  59.                   ent.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$H$7"
  60.                   Set ent = ent.Offset(1)
  61.                   inc.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$I$7"
  62.                   Set inc = inc.Offset(1)
  63.                   falta.Formula = "='" & file.ParentFolder & "\[" & file.Name & "]Folha1'!$J$7"
  64.                   Set falta = falta.Offset(1)
  65.                   c = c + 1
  66.                   Range(Cells(c, 3), Cells(c, 3)).Select
  67.                End If
  68.              End If
  69.             Next
  70.          Next
  71.  
  72. tamanho = Range("C65536").End(xlUp).Row
  73.   Range(Cells(10, 3), Cells(tamanho, 9)).Select
  74.  
  75.     Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  76.     Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  77.     With Selection.Borders(xlEdgeLeft)
  78.         .LineStyle = xlDouble
  79.         .ColorIndex = 0
  80.         .TintAndShade = 0
  81.         .Weight = xlThick
  82.     End With
  83.     With Selection.Borders(xlEdgeTop)
  84.         .LineStyle = xlDouble
  85.         .ColorIndex = 0
  86.         .TintAndShade = 0
  87.         .Weight = xlThick
  88.     End With
  89.     With Selection.Borders(xlEdgeBottom)
  90.         .LineStyle = xlDouble
  91.         .ColorIndex = 0
  92.         .TintAndShade = 0
  93.         .Weight = xlThick
  94.     End With
  95.     With Selection.Borders(xlEdgeRight)
  96.         .LineStyle = xlDouble
  97.         .ColorIndex = 0
  98.         .TintAndShade = 0
  99.         .Weight = xlThick
  100.     End With
  101.     With Selection.Borders(xlInsideVertical)
  102.         .LineStyle = xlContinuous
  103.         .ColorIndex = 0
  104.         .TintAndShade = 0
  105.         .Weight = xlThin
  106.     End With
  107.     With Selection.Borders(xlInsideHorizontal)
  108.         .LineStyle = xlContinuous
  109.         .ColorIndex = 0
  110.         .TintAndShade = 0
  111.         .Weight = xlThin
  112.     End With
  113.    
  114.         Set ot = ActiveSheet.Cells(10, 3)
  115.        Set ent = ActiveSheet.Cells(10, 7)
  116.        Set inc = ActiveSheet.Cells(10, 8)
  117.        Set falta = ActiveSheet.Cells(10, 9)
  118.        For l = 10 To tamanho
  119.        If ent <> 0 Then
  120.          If inc = 0 Then
  121.            If falta = 0 Then ot.Interior.ColorIndex = 43
  122.            
  123.                     End If
  124.                    End If
  125.                 Set ot = ot.Offset(1)
  126.             Set ent = ent.Offset(1)
  127.             Set inc = inc.Offset(1)
  128.             Set falta = falta.Offset(1)
  129.             Next l
  130.  
  131. Application.GoTo Reference:=Worksheets("Sobressalentes_por_OT").Range("B7"), scroll:=True
  132.  
  133. End With
  134. End Sub
  135.  
  136.  
  137.  
  138. https://lh3.googleusercontent.com/-lB9vFgXgQiw/TmeWtgGaA2I/AAAAAAAAA7k/3tN1sFHPb0g/s979/quadro%2Bresumo%2Brequisi%25C3%25A7%25C3%25B5es.jpg
Advertisement
Add Comment
Please, Sign In to add comment