Advertisement
Guest User

Untitled

a guest
Nov 14th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public fs As New FileSystemObject
  2.  
  3.  
  4. Function GetPlant(Name As String)
  5.     If InStr(1, Name, "SPC") Then
  6.         If InStr(1, Name, "A Plant") Then
  7.             GetPlant = "A"
  8.         Else
  9.             GetPlant = "B"
  10.         End If
  11.     Else
  12.         GetPlant = "NO"
  13.     End If
  14. End Function
  15.  
  16. Function DirName(Path As String)
  17.     DirName = Left(Path, InStrRev(Path, "\") - 1)
  18. End Function
  19.  
  20. Function BaseName(Path As String)
  21.     BaseName = Right(Path, Len(Path) - InStrRev(Path, "\"))
  22. End Function
  23.  
  24.  
  25. Sub OpenBooks(pl As String, Optional skip As Boolean = False)
  26.     Dim response As Boolean
  27.     Dim fldr As Folder
  28.     Dim f As File
  29.        
  30.     If Not skip Then
  31.         skip = MsgBox("Do you want to open all " & pl & " Plant charts?", vbYesNo) = 6
  32.     End If
  33.    
  34.     If skip Then
  35.         Set fldr = fs.GetFolder(ThisWorkbook.Path & "\" & pl & " Plant")
  36.        
  37.         For Each f In fldr.Files
  38.             Application.Workbooks.Open (f.Path)
  39.         Next f
  40.     End If
  41. End Sub
  42.  
  43. Sub ChangeSheets(pl As String, Optional skip As Boolean = False)
  44.     Dim response As Boolean
  45.     Dim month As String
  46.     Dim wb As Workbook
  47.     Dim ws As Worksheet
  48.        
  49.     If Not skip Then
  50.         skip = MsgBox("Do you want to modify all " & pl & " Plant charts?", vbYesNo) = 6
  51.     End If
  52.    
  53.     month = ThisWorkbook.ActiveSheet.Range("Month").Value
  54.  
  55.     If skip Then
  56.         For Each wb In Application.Workbooks
  57.             If pl = GetPlant(wb.Name) Then
  58.                 wb.Worksheets("Data").Range("B1").Value = month
  59.             End If
  60.         Next wb
  61.     End If
  62. End Sub
  63.  
  64. Sub PrintSheets(pl As String, Optional skip As Boolean = False)
  65.     Dim response As Boolean
  66.     Dim wb As Workbook
  67.     Dim ws As Worksheet
  68.        
  69.     If Not skip Then
  70.         skip = MsgBox("Do you want to print all " & pl & " Plant charts?", vbYesNo) = 6
  71.     End If
  72.  
  73.     If skip Then
  74.         For Each wb In Application.Workbooks
  75.             If pl = GetPlant(wb.Name) Then
  76.                 For Each ws In wb.Worksheets
  77.                     If ws.Name <> "Data" Then
  78.                         MsgBox "Fake print!" 'ws.PrintOut
  79.                    End If
  80.                 Next ws
  81.             End If
  82.         Next wb
  83.     End If
  84. End Sub
  85.  
  86. Sub CloseBooks(pl As String, Optional skip As Boolean = False)
  87.     Dim response As Boolean
  88.     Dim wb As Workbook
  89.    
  90.     If Not skip Then
  91.         skip = MsgBox("Do you want to save and close all " & pl & " Plant charts?", vbYesNo) = 6
  92.     End If
  93.  
  94.     If skip Then
  95.         For Each wb In Application.Workbooks
  96.             If pl = GetPlant(wb.Name) Then
  97.                 wb.Close True
  98.             End If
  99.         Next wb
  100.     End If
  101. End Sub
  102.  
  103.  
  104. Sub OpenA()
  105.     OpenBooks "A"
  106. End Sub
  107.  
  108. Sub OpenB()
  109.     OpenSheets "B"
  110. End Sub
  111.  
  112.  
  113. Sub ChangeASheets()
  114.     ChangeSheets "A"
  115. End Sub
  116.  
  117. Sub ChangeBSheets()
  118.     ChangeSheets "B"
  119. End Sub
  120.  
  121.  
  122. Sub PrintASheets()
  123.     PrintSheets "A"
  124. End Sub
  125.  
  126. Sub PrintBSheets()
  127.     PrintSheets "B"
  128. End Sub
  129.  
  130.  
  131. Sub CloseA()
  132.     CloseBooks "A"
  133. End Sub
  134.  
  135. Sub CloseB()
  136.     CloseBooks "B"
  137. End Sub
  138.  
  139.  
  140. Sub AAll(Optional skip As Boolean = False)
  141.     If MsgBox("Do you want to open, modify, print, save, and close all A Plant charts?", vbYesNo) = 6 Then
  142.         OpenBooks "A", True
  143.         ChangeSheets "A", True
  144.         PrintSheets "A", True
  145.         CloseBooks "A", True
  146.     End If
  147. End Sub
  148.  
  149. Sub BAll(Optional skip As Boolean = False)
  150.     If MsgBox("Do you want to open, modify, print, save, and close all B Plant charts?", vbYesNo) = 6 Then
  151.         OpenBooks "B", True
  152.         ChangeSheets "B", True
  153.         PrintSheets "B", True
  154.         CloseBooks "B", True
  155.     End If
  156. End Sub
  157.  
  158. Sub AllAll()
  159.     If MsgBox("Do you want to open, modify, print, save, and close ALL SPC charts?", vbYesNo) = 6 Then
  160.         AAll True
  161.         BAll True
  162.     End If
  163. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement