Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub mReports_Project_1()
- Dim stReportingTimeRaw As String
- Set ThisWb = ActiveWorkbook
- st_RPRT_Folder = "(1) Ìàòðèöà ñòðîêè äåêëàðàöèè - Îïåðàöèè"
- If bBulkReporting = False Then
- If MsgBox("Âû ñîáèðàåòåñü ñôîðìèðîâàòü îò÷åò:" _
- & Chr(10) _
- & Chr(10) _
- & "(1) Ìàòðèöà âçàèìîñâÿçè ñòðîê íàëîãîâûõ äåêëàðàöèé è õîçÿéñòâåííûõ îïåðàöèé, îòäåëüíûõ ýòàïîâ ÁÏ" _
- & Chr(10) _
- & Chr(10) _
- & Chr(10) _
- & "Ïðîäîëæèòü?", vbYesNo) <> vbYes Then
- Exit Sub
- End If
- End If
- 'MsgBox ("REPORT")
- '''''''''ÏÀÏÊÀ "Îò÷åòû SmartTemplate"
- If Not FolderExists(ThisWb.path & "\" & stReportFolder) Then
- FolderCreate ThisWb.path & "\" & stReportFolder 'Else MsgBox ("Ïàïêà óæå ñóùåñòâóåò")
- End If
- '''''''''ÏÀÏÊÀ "Ïðîåêòíûå îò÷åòû"
- If Not FolderExists(ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project) Then
- FolderCreate ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project
- End If
- '''''''''ÏÀÏÊÀ "#ÈÌß ÎÒ×åÒÀ"
- If Not FolderExists(ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project & "\" & st_RPRT_Folder) Then
- FolderCreate ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project & "\" & st_RPRT_Folder
- End If
- 'ÑÎÇÄÀÒÜ ÏÀÏÊÓ "#ÄÀÒÀ ÎÒ×åÒÀ"
- If bBulkReporting = False Then
- stReportingTimeRaw = Now
- stReportingTime = strLegalFileName(stReportingTimeRaw)
- st_RPRT_Time_Folder = stReportingTime
- Else
- st_RPRT_Time_Folder = stBulkReportingTime
- End If
- If Not FolderExists(ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project & "\" & st_RPRT_Folder & "\" & st_RPRT_Time_Folder) Then
- FolderCreate ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project & "\" & st_RPRT_Folder & "\" & st_RPRT_Time_Folder
- End If
- '''''''''''''''''''''''''''''''''''''''''
- '''''''''''''''''''''''''''''''''''''''''
- 'ÑÎÇÄÀÒÜ ÎÒ×åÒ ÍÀ ÄÀÒÓ
- '''''''''''''''''''''''''''''''''''''''''
- '''''''''''''''''''''''''''''''''''''''''
- Prepare
- Set RprtWb = Workbooks.Add
- 'Îãðàíè÷åíèå 218 ñèìâîëîâ
- iErrLength218ExceedCount = 0
- stFullFolderPath = ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project & "\" & st_RPRT_Folder & "\" & st_RPRT_Time_Folder & "\"
- iFullFolderPath = Len(ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project & "\" & st_RPRT_Folder & "\" & st_RPRT_Time_Folder & "\")
- stFullFilePath = Left(ThisWb.path & "\" & stReportFolder & "\" & stReportFolder_Project & "\" & st_RPRT_Folder & "\" & st_RPRT_Time_Folder & "\" & st_RPRT_Folder, 186) & "... îò " & st_RPRT_Time_Folder & ".xlsx"
- If iFullFolderPath >= 187 Then
- iErrLength218ExceedCount = iErrLength218ExceedCount + 1
- RprtWb.Close
- Else
- 'Äåëàåì îò÷¸ò
- RprtWb.Activate
- Set RprtSht = ActiveSheet
- RprtSht.Name = st_RPRT_Time_Folder
- 'lLastRow_rprt = ThisWb.Sheets("tt_CPRisk").Cells(Rows.Count, 2).End(xlUp).Row
- 'ThisWb.Sheets("tt_CPRisk").Range("A1:D" & lLastRow_rprt).Copy
- 'RprtWb.Sheets(RprtSht.Name).Range("A1").PasteSpecial (xlPasteValues)
- RprtWb.Sheets(RprtSht.Name).Cells(3, 2).Value = "¹"
- RprtWb.Sheets(RprtSht.Name).Cells(3, 3).Value = "Ïðîöåññ 1 óðîâíÿ"
- RprtWb.Sheets(RprtSht.Name).Cells(3, 4).Value = "Ïðîöåññ 2 óðîâíÿ"
- RprtWb.Sheets(RprtSht.Name).Cells(3, 5).Value = "Ïîäïðîöåññ 3 óðîâíÿ"
- RprtWb.Sheets(RprtSht.Name).Cells(3, 6).Value = "Ïîäïðîöåññ 4 óðîâíÿ"
- RprtWb.Sheets(RprtSht.Name).Cells(3, 7).Value = "Äåêëàðàöèÿ"
- RprtWb.Sheets(RprtSht.Name).Cells(3, 8).Value = "Ëèñò"
- RprtWb.Sheets(RprtSht.Name).Cells(3, 9).Value = "Ïðèëîæåíèå"
- RprtWb.Sheets(RprtSht.Name).Cells(3, 10).Value = "Ñòðîêà"
- 'RprtWb.Sheets(RprtSht.Name).Cells(3, 10).Value = "Ñòàòóñ ïîêðûòèÿ"
- iRprtLine = 4 'Ïåðâàÿ ñòðîêà îò÷¸òà
- With ThisWb
- With .Sheets("ref_Operations")
- iProcessLastRow = .Cells(.Rows.Count, 3).End(xlUp).Row
- For iProcessElem = 5 To iProcessLastRow 'Ïî âñåì ïðîöåññàì
- '(1)Ïèøåì â îò÷¸ò ñòðîêó
- ' (1.1) Èíèöèàëèçèðóåì ïåðåìåííûå
- stDecl_PROCESS_1 = .Cells(iProcessElem, 4).Value
- stDecl_PROCESS_2 = .Cells(iProcessElem, 5).Value
- stDecl_PROCESS_3 = .Cells(iProcessElem, 6).Value
- stDecl_PROCESS_4 = .Cells(iProcessElem, 7).Value
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 2).Value = iRprtLine - 3
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 3).Value = stDecl_PROCESS_1
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 4).Value = stDecl_PROCESS_2
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 5).Value = stDecl_PROCESS_3
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 6).Value = stDecl_PROCESS_4
- 'RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 6).Value = stDecl_STRING
- ' (1.2) Èùåì ÊÏ ó êîòîðûõ åñòü ýòîò ïðîöåññ
- iCPLastRow = ThisWb.Sheets("tt_CPOperations").Cells(Rows.Count, 2).End(xlUp).Row
- bCPtoRiskAdded = False
- For iCP = 4 To iCPLastRow
- If ThisWb.Sheets("tt_CPOperations").Cells(iCP, 3) = stDecl_PROCESS_1 _
- And ThisWb.Sheets("tt_CPOperations").Cells(iCP, 4) = stDecl_PROCESS_2 _
- And ThisWb.Sheets("tt_CPOperations").Cells(iCP, 5) = stDecl_PROCESS_3 _
- And ThisWb.Sheets("tt_CPOperations").Cells(iCP, 6) = stDecl_PROCESS_4 _
- Then
- 'Åñòü ÊÏ ó êîòîðûõ åñòü ýòîò ïðîöåññ
- 'Ïîëó÷àåì êîä ÊÏ â SmartTemplate
- stCP_CodeST = ThisWb.Sheets("tt_CPOperations").Cells(iCP, 2)
- 'stDecl_STRING = ThisWb.Sheets("tt_CPDeclHierarchy").Cells(iCP, 6)
- 'Äîáàâëÿåì çàïèñü â ñòðîêó îò÷¸òà
- ''''START ïîâòîðÿåì çàïèñè'''''
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 2).Value = iRprtLine - 3
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 3).Value = stDecl_PROCESS_1
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 4).Value = stDecl_PROCESS_2
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 5).Value = stDecl_PROCESS_3
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 6).Value = stDecl_PROCESS_4
- ''''END ïîâòîðÿåì çàïèñè'''''
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 7).Value = stCP_CodeST '"Äåêëàðàöèÿ"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 8).Value = "Ëèñò" '"Ñèñòåìíûé êîä ÊÏ"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 9).Value = "Ïðèëîæåíèå"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 10).Value = "Ñòðîêà"
- 'Èùåì ñòðîêè íàëîãîâîé äåêëàðàöèè ïî êîíòðîëþ, ó êîòîðîãî åñòü ïðîöåññ
- i_tt_CPDeclHierarchy_LastRow = ThisWb.Sheets("tt_CPDeclHierarchy").Cells(Rows.Count, 2).End(xlUp).Row
- For i_tt_CPDeclHierarchy_Current = 4 To i_tt_CPDeclHierarchy_LastRow
- If ThisWb.Sheets("tt_CPDeclHierarchy").Cells(i_tt_CPDeclHierarchy_Current, 2) = stCP_CodeST Then
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 7).Value = ThisWb.Sheets("tt_CPDeclHierarchy").Cells(i_tt_CPDeclHierarchy_Current, 3).Value
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 8).Value = ThisWb.Sheets("tt_CPDeclHierarchy").Cells(i_tt_CPDeclHierarchy_Current, 4).Value
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 9).Value = ThisWb.Sheets("tt_CPDeclHierarchy").Cells(i_tt_CPDeclHierarchy_Current, 5).Value
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 10).Value = ThisWb.Sheets("tt_CPDeclHierarchy").Cells(i_tt_CPDeclHierarchy_Current, 6).Value
- ''''START ïîâòîðÿåì çàïèñè''''''
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 2).Value = iRprtLine - 3
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 3).Value = stDecl_PROCESS_1
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 4).Value = stDecl_PROCESS_2
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 5).Value = stDecl_PROCESS_3
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 6).Value = stDecl_PROCESS_4
- '''''END ïîâòîðÿåì çàïèñè''''''
- 'Ïåðåâîäèì íà íîâóþ ñòðîêó äëÿ íîâîé ñòðîêè äåêëàðàöèè ÊÏ
- iRprtLine = iRprtLine + 1
- bCPtoRiskAdded = True
- End If
- Next i_tt_CPDeclHierarchy_Current
- 'Ïåðåâîäèì íà íîâóþ ñòðîêó äëÿ íîâîé ÊÏ
- 'iRprtLine = iRprtLine + 1
- 'bCPtoRiskAdded = True
- End If
- Next iCP
- 'Íåò ÊÏ ó êîòîðûõ åñòü ýòà îïåðàöèÿ
- If bCPtoRiskAdded = False Then
- 'Åñëè 4 óðîâåíü åñòü, íî íå íàéäåíà ÊÏ
- If .Cells(iProcessElem, 7).Value <> "" Then
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 7).Value = "Íåò âëèÿíèÿ"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 8).Value = "-"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 9).Value = "-"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 10).Value = "-"
- End If
- 'Åñëè 4 óðîâíÿ íåò, òîãäà
- ''''3 óðîâåíü ëèáî àãðåãàöèîííûé ëèáî ïîñëåäíèé
- ''''''''Åñëè àãðåãàöèîííûé
- If .Cells(iProcessElem, 7).Value = "" Then
- If .Cells(iProcessElem, 6).Value <> "" _
- And .Cells(iProcessElem + 1, 6).Value <> .Cells(iProcessElem, 6).Value Then
- 'Êîíå÷íûé
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 7).Value = "Íåò âëèÿíèÿ"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 8).Value = "-"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 9).Value = "-"
- RprtWb.Sheets(RprtSht.Name).Cells(iRprtLine, 10).Value = "-"
- Else
- 'àãðåãàöèîííûé
- End If
- End If
- iRprtLine = iRprtLine + 1
- End If
- Next iProcessElem
- End With '
- End With 'ThisWb
- RprtWb.Sheets(RprtSht.Name).ListObjects.Add(xlSrcRange, Range("$B$3:$J$" & (3 + iProcessElem)), , xlYes).Name = "Project_1"
- ActiveSheet.ListObjects("Project_1").TableStyle = "TableStyleLight9"
- RprtWb.Sheets(RprtSht.Name).Cells.RowHeight = 15
- RprtWb.SaveAs stFullFilePath
- RprtWb.Close
- End If
- Ended
- '''''''''''''''''''''''''''''''''''''''''
- '''''''''''''''''''''''''''''''''''''''''
- ThisWb.Sheets("MAIN").Unprotect Password:=stWorkbookPassword
- If iErrLength218ExceedCount = 0 Then
- ThisWb.Sheets("MAIN").Hyperlinks.Add _
- Anchor:=ThisWb.Sheets("MAIN").Range("ref_cell_MAIN_REPORTS_Project_1_Link"), _
- Address:=stFullFilePath, _
- TextToDisplay:=st_RPRT_Folder & " îò " & st_RPRT_Time_Folder & ".xlsx"
- ThisWb.Sheets("MAIN").Range("ref_cell_MAIN_REPORTS_Project_1_Link").Offset(-2, 0).Value = iRprtLine - 3
- If bBulkReporting = False Then ThisWb.Sheets("MAIN").Cells(Range("ref_cell_MAIN_REPORTS_Project_1_Link").Row - 2, Range("ref_cell_MAIN_REPORTS_Project_1_Link").Column + 2) = stReportingTimeRaw
- If bBulkReporting = True Then ThisWb.Sheets("MAIN").Cells(Range("ref_cell_MAIN_REPORTS_Project_1_Link").Row - 2, Range("ref_cell_MAIN_REPORTS_Project_1_Link").Column + 2) = stBulkReportingTimeRaw
- ThisWb.Sheets("MAIN").Range("ref_cell_MAIN_REPORTS_Project_1_Link").Offset(-2, 2).Value = Environ("UserName")
- Else
- ThisWb.Sheets("MAIN").Range("ref_cell_MAIN_REPORTS_Project_1_Link").Value = "Îøèáêà ñîçäàíèÿ îò÷åòà: ïîëíûé ïóòü ôàéëà <" & stFullFilePath & "> ïðåâûøàåò 218 ñèìâîëîâ (ñèñòåìíîå îãðàíè÷åíèå). Ïîæàëóéñòà, âûáåðèòå áîëåå êîðîòêóþ äèðåêòîðèþ õðàíåíèÿ SmartTemplate è ïåðåçàïóñòèòå ôîðìèðîâàíèå îò÷åòîâ"
- ThisWb.Sheets("MAIN").Range("ref_cell_MAIN_REPORTS_Project_1_Link").Offset(-2, 0).Value = "-"
- If bBulkReporting = False Then ThisWb.Sheets("MAIN").Cells(Range("ref_cell_MAIN_REPORTS_Project_1_Link").Row - 2, Range("ref_cell_MAIN_REPORTS_Project_1_Link").Column + 2) = stReportingTimeRaw
- If bBulkReporting = True Then ThisWb.Sheets("MAIN").Cells(Range("ref_cell_MAIN_REPORTS_Project_1_Link").Row - 2, Range("ref_cell_MAIN_REPORTS_Project_1_Link").Column + 2) = stBulkReportingTimeRaw
- ThisWb.Sheets("MAIN").Range("ref_cell_MAIN_REPORTS_Project_1_Link").Offset(-2, 4).Value = Environ("UserName")
- End If
- ThisWb.Sheets("MAIN").Protect Password:=stWorkbookPassword, UserInterfaceOnly:=True
- If bBulkReporting = False Then MsgBox ("Îò÷¸ò ñôîðìèðîâàí")
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement