Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim conn As New ADODB.Connection
- Dim connString As String
- Dim rs As New ADODB.Recordset
- Dim conn2 As New ADODB.Connection
- Dim connString2 As String
- Dim rs2 As New ADODB.Recordset
- Dim ciclo() As String
- Dim ciclo_pop() As String
- Dim ciclo_placa() As String
- Dim mux() As String
- Public Type modens
- nome As String
- cor_fonte As String
- linha As Integer
- novo_nome As String
- End Type
- Public Type tipo_modem
- nome As String
- seq As Integer
- End Type
- Public Type placas
- nome As String
- seq As Integer
- End Type
- Public Type portas
- nome As String
- seq As Integer
- End Type
- Public Type canalizados
- facilidade As String
- circuito As String
- vc As String
- aba As String
- arquivo As String
- subend As String
- End Type
- Public Type array_canal
- n64 As String
- ts As String
- facilidade As String
- End Type
- Public Type ultima_milha
- mux As String
- circuito As String
- aba As String
- arquivo As String
- subend As String
- end2 As String
- porta_mux As String
- tipo_mux As String
- slot_mux As String
- status_circ As String
- cliente_circ As String
- placa As String
- End Type
- Private Sub ConnectDB()
- 'CONECTA NO BANCO DA MYSQL - necessita do driver ODBC
- Set conexao = New ADODB.Connection
- conexao.Open "DRIVER={MySQL ODBC 5.2 ANSI Driver};" & _
- "SERVER=mysql.infovias.unix.corp;" & _
- "DATABASE=sicop;" & _
- "USER=sicop;" & _
- "PASSWORD=sicop;" & _
- "Option=3"
- End Sub
- Public Sub main()
- Application.ScreenUpdating = False
- Dim FSO As New FileSystemObject
- Dim array_ultimamilha() As Variant
- ReDim Preserve array_ultimamilha(0)
- 'obter pasta temporaria
- profile_folder = GetSpecialFolderPaths()
- arquivos_RMBH = Array("Controle_RMBHE_1.xlsx", "Controle_RMBHE_2.xlsx", "Controle_RMBHE_3.xlsx", "Controle_RMBHE_4.xlsx", "Controle_RMBHE_5.xlsx", "Controle_RMBHE_6.xlsx", "Controle_RMBHE_7.xlsx", "Controle_RMBHE_8.xlsx", "Vesper.xlsx")
- arquivos_interior = Array("Pops_e_Sites_Interior_Leste.xlsx", "Pops_e_Sites_Interior_Oeste.xlsx", "Pops_e_Sites_Interior_Norte.xlsx", "Pops_e_Sites_Interior_Sul.xlsx", "Pops_e_Sites_Interior_Sudeste.xlsx", "Pops_e_Sites_Outros_Estados.xlsx")
- 'arquivos_RMBH = Array("Controle_RMBHE_2.xlsx")
- check_profile_folder = profile_folder & "\SICOP"
- If FileFolderExists((check_profile_folder)) = True Then
- Clear_All_Files_And_SubFolders_In_Folder (check_profile_folder)
- End If
- destino_folder = profile_folder & "\SICOP\"
- If FileFolderExists((destino_folder)) = False Then
- create_folder (destino_folder)
- End If
- 'copiar arquivos do controle de facilidades
- destino_folder = profile_folder & "\SICOP\Facilidades\"
- create_folder (destino_folder)
- destino_folder = profile_folder & "\SICOP\Facilidades\Controle\"
- create_folder (destino_folder)
- For i = 0 To UBound(arquivos_RMBH)
- origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Região_Metropolitana\" & arquivos_RMBH(i)
- retorno_copy = Copy_One_File((origem_folder), (destino_folder))
- Next
- For i = 0 To UBound(arquivos_interior)
- origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Interior\" & arquivos_interior(i)
- retorno_copy = Copy_One_File((origem_folder), (destino_folder))
- Next
- destino_folder = profile_folder & "\SICOP\Comercial\"
- create_folder (destino_folder)
- origem_folder = "\\file_server\Viabilidades\Banco_OS\BD_ATIVACOES.mdb"
- retorno_copy = Copy_One_File((origem_folder), (destino_folder))
- destino_folder = profile_folder & "\SICOP\Auxiliar\"
- create_folder (destino_folder)
- origem_folder = "\\fileserver\publico\SICOP\Script_Macro\hierarquias.xlsx"
- retorno_copy = Copy_One_File((origem_folder), (destino_folder))
- destino_folder = profile_folder & "\SICOP\Auxiliar\"
- origem_folder = "\\fileserver\publico\SICOP\Script_Macro\operadoras.xlsx"
- retorno_copy = Copy_One_File((origem_folder), (destino_folder))
- destino_folder = profile_folder & "\SICOP\Facilidades\Operadoras\"
- create_folder (destino_folder)
- destino_folder = profile_folder & "\SICOP\Facilidades\Operadoras\RMBH\"
- create_folder (destino_folder)
- origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Região_Metropolitana\Operadoras"
- retorno_copy = Copy_Folder((origem_folder), (destino_folder))
- destino_folder = profile_folder & "\SICOP\Facilidades\Operadoras\Interior\"
- create_folder (destino_folder)
- origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Interior\Operadoras_e_canalizados"
- retorno_copy = Copy_Folder((origem_folder), (destino_folder))
- destino_folder = profile_folder & "\SICOP\Facilidades\Canalizados\"
- create_folder (destino_folder)
- destino_folder = profile_folder & "\SICOP\Facilidades\Canalizados\RMBH\"
- create_folder (destino_folder)
- origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Região_Metropolitana\Canalizados\Canalizados VC-12"
- retorno_copy = Copy_Folder((origem_folder), (destino_folder))
- destino_folder = profile_folder & "\SICOP\Facilidades\Canalizados\Interior\"
- create_folder (destino_folder)
- origem_folder = "\\db_server\Facilidades\Controle_de_Facilidades\Interior\Canalizados"
- retorno_copy = Copy_Folder((origem_folder), (destino_folder))
- For i = 0 To UBound(arquivos_RMBH)
- valor = profile_folder & "\SICOP\Facilidades\Controle\" + arquivos_RMBH(i)
- 'valor = "\\db_server\Facilidades\Controle_de_Facilidades\Região_Metropolitana\" + arquivos_RMBH(i)
- array_ultimamilha(UBound(array_ultimamilha)) = valor
- ReDim Preserve array_ultimamilha(UBound(array_ultimamilha) + 1)
- Next
- For i = 0 To UBound(arquivos_interior)
- 'valor = "\\db_server\Facilidades\Controle_de_Facilidades\Interior\" + arquivos_interior(i)
- valor = profile_folder & "\SICOP\Facilidades\Controle\" + arquivos_interior(i)
- array_ultimamilha(UBound(array_ultimamilha)) = valor
- ReDim Preserve array_ultimamilha(UBound(array_ultimamilha) + 1)
- Next
- ReDim Preserve array_ultimamilha(UBound(array_ultimamilha) - 1)
- principal = ActiveWorkbook.Name
- Workbooks.Add
- ActiveWorkbook.Activate
- tabelao = ActiveWorkbook.Name
- Windows(tabelao).Activate
- ActiveWindow.Zoom = 75
- 'planilha_UM = ultimamilha(array_ultimamilha(), (tabelao))
- path_PM = profile_folder & "\SICOP\Facilidades\Operadoras\"
- 'planilha_PM = primeiramilha((path_PM))
- 'planilha_canalizados = canalizados_pla(array_ultimamilha())
- path_comercial = profile_folder & "\SICOP\Comercial\BD_ATIVACOES.mdb"
- planilha_comercial = compara_eng_com(array_ultimamilha, path_comercial, path_PM)
- 'Windows(planilha_UM).Activate
- 'Sheets("Plan1").Name = "Ultima_Milha"
- 'Sheets("Ultima_Milha").Move After:=Workbooks(tabelao).Sheets(1)
- 'Windows(planilha_PM).Activate
- 'Sheets("Plan1").Name = "Primeira_Milha"
- 'Sheets("Primeira_Milha").Move After:=Workbooks(tabelao).Sheets(1)
- 'Windows(planilha_canalizados).Activate
- 'Sheets("Plan1").Name = "Canalizados"
- '
- 'Sheets("Canalizados").Move After:=Workbooks(tabelao).Sheets(1)
- '
- 'Windows(planilha_comercial).Activate
- '
- 'Sheets("Plan1").Name = "Comercial"
- '
- 'Sheets("Comercial").Move After:=Workbooks(tabelao).Sheets(1)
- '
- 'Windows(tabelao).Activate
- '
- 'Sheets("Plan1").Name = "Todas_Facilidades"
- '
- Application.ScreenUpdating = True
- '
- End Sub
- Public Function compara_eng_com(Filename As Variant, path_comercial As Variant, path_PM As Variant) As String
- Dim sheet As Worksheet
- Dim celula, celula1 As Range
- Dim LastRow As Long
- Dim Filter As String
- Dim FilterIndex As Integer
- 'Dim filename As Variant
- Dim remove As String
- Dim path As String
- 'Dim canalizados() As canalizado
- 'Dim array_temp() As array_canal
- 'ReDim Preserve canalizados(0)
- ' ReDim Preserve array_temp(0)
- Dim ultima_milha() As ultima_milha
- Dim comercial() As String
- ReDim Preserve ultima_milha(0)
- ReDim Preserve comercial(0)
- connString = "DSN=sicop_prod2;Uid=sicop_prod2;Pwd=sicop_prod2"
- If conn.State = adStateOpen Then
- conn.Close
- End If
- conn.Open connString
- rs.LockType = adLockBatchOptimistic
- rs.CursorLocation = adUseClient
- rs2.LockType = adLockBatchOptimistic
- rs2.CursorLocation = adUseClient
- 'Não atualizar a tela durante o script.
- 'Application.ScreenUpdating = False
- ' File filters - Filtro dos tipos de arquivos que aparecem na caixa de dialogo de escolha do arquivo.
- 'Filter = "Excel Files (*.xls),*.xls," & _
- '"Text Files (*.txt),*.txt," & _
- '"All Files (*.*),*.*"
- ' Default filter to *.*
- 'FilterIndex = 3
- ' Set Dialog Caption
- 'TITULO DA CAIXA
- 'Title = "Escolha o arquivo de circuitos "
- ' Select Start Drive & Path - Caminho da caixa de dialogo.
- 'ChDrive ("C")
- 'ChDir ("C:\")
- 'ABRE CADA ARQUIVO SELECIONADO DA CAIXA DE DIALOGO
- 'With Application
- 'Set File Name Array to selected Files (allow multiple)
- 'Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
- 'Reset Start Drive/Path
- 'ChDrive (Left(.DefaultFilePath, 1))
- 'ChDir (.DefaultFilePath)
- 'End With
- 'Exit on Cancel
- ' File filters
- 'Filter = "Excel Files (*.xls),*.xls," & _
- ' "Text Files (*.txt),*.txt," & _
- ' "All Files (*.*),*.*"
- '' Default filter to *.*
- 'FilterIndex = 3
- '' Set Dialog Caption
- 'Title = "Escolha o arquivo de circuitos da Engenharia"
- '' Select Start Drive & Path
- 'ChDrive ("C")
- 'ChDir ("C:\Users\acunha\Desktop\Trabalho\Engenharia")
- 'With Application
- ' ' Set File Name Array to selected Files (allow multiple)
- ' Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
- ' ' Reset Start Drive/Path
- ' ChDrive (Left(.DefaultFilePath, 1))
- ' ChDir (.DefaultFilePath)
- 'End With
- '' Exit on Cancel
- '
- 'If Not IsArray(Filename) Then
- ' MsgBox "Nenhum arquivo selecionado."
- ' Exit Function
- 'End If
- principal = ActiveWorkbook.Name
- ' Workbooks.Add
- ' ActiveWorkbook.Activate
- ' erros = ActiveWorkbook.Name
- ' Open Files
- For sasa = LBound(Filename) To UBound(Filename) ' FOR abre arquivos
- msg = msg & Filename(sasa) & vbCrLf ' This can be removed
- Workbooks.Open Filename(sasa), False
- arquivo = ActiveWorkbook.Name
- If arquivo Like "*Interior*" Then
- caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Interior"
- Else
- caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Região_Metropolitana"
- End If
- end2 = (caminhoarquivo & "\" & arquivo)
- Windows(arquivo).Activate
- For Each sheet In ActiveWorkbook.Worksheets
- If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- sheet.Select
- aba = sheet.Name
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- For Each celula In Range("C3:C" & LastRow)
- linha = celula.Row
- If Range("C" & linha).Interior.ColorIndex = 1 Then
- mux_milha = Range("C" & linha).Value
- End If
- If Range("C" & linha).Interior.ColorIndex <> 1 And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("C" & linha)) Then
- velocidade = Range("D" & linha).Value
- status_circ = Range("B" & linha).Value
- cliente_circ = Range("G" & linha).Value
- If Not IsEmpty(Range("K" & linha)) Or Range("K" & linha).Value <> "" Then
- placa = Range("K" & linha).Value
- End If 'If Not IsEmpty(Range("K" & linha)) Or Range("K" & linha).Value <> "" Then
- If Not IsEmpty(Range("L" & linha)) Or Range("L" & linha).Value <> "" Then
- slot_mux = Range("L" & linha).Value
- End If 'If Not IsEmpty(Range("K" & linha)) Or Range("K" & linha).Value <> "" Then
- If Not IsEmpty(Range("M" & linha)) Or Range("M" & linha).Value <> "" Then
- porta = Range("M" & linha).Value
- End If 'If Not IsEmpty(Range("K" & linha)) Or Range("K" & linha).Value <> "" Then
- ' canal = checa_canalizado(velocidade)
- ' If canal = 1 Then
- If InStr(1, Range("C" & linha).Value, " ") <> 0 Then
- Range("C" & linha).Value = Replace(Range("C" & linha).Value, " ", " ")
- ElseIf InStr(1, Range("C" & linha).Value, " ") <> 0 Then
- Range("C" & linha).Value = Replace(Range("C" & linha).Value, " ", " ")
- End If
- ultima_milha(UBound(ultima_milha)).circuito = UCase(Trim(Range("C" & linha).Value))
- ultima_milha(UBound(ultima_milha)).mux = mux_milha
- ultima_milha(UBound(ultima_milha)).arquivo = arquivo
- ultima_milha(UBound(ultima_milha)).aba = aba
- ' ultima_milha(UBound(ultima_milha)).subend = ("'" & aba & "'!" & Removedolars(Range("C" & linha).Address))
- ultima_milha(UBound(ultima_milha)).end2 = end2
- ultima_milha(UBound(ultima_milha)).status_circ = status_circ
- ultima_milha(UBound(ultima_milha)).cliente_circ = cliente_circ
- ultima_milha(UBound(ultima_milha)).slot_mux = slot_mux
- ultima_milha(UBound(ultima_milha)).placa = placa
- ultima_milha(UBound(ultima_milha)).porta_mux = porta
- ReDim Preserve ultima_milha(UBound(ultima_milha) + 1)
- ' End If ' If canal = 1 Then
- End If 'If Range("C" & linha).Interior.ColorIndex <> 1 And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("C" & linha)) Then
- Next
- End If ' If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- Next 'For Each sheet In ActiveWorkbook.Worksheets
- Windows(arquivo).Close False
- Next
- '
- '
- '' File filters
- 'Filter = "Excel Files (*.xls),*.xls," & _
- ' "Text Files (*.txt),*.txt," & _
- ' "All Files (*.*),*.*"
- '' Default filter to *.*
- 'FilterIndex = 3
- '' Set Dialog Caption
- 'Title = "Escolha o arquivo de circuitos do Comercial"
- '' Select Start Drive & Path
- 'ChDrive ("C")
- 'ChDir ("C:\")
- 'With Application
- ' ' Set File Name Array to selected Files (allow multiple)
- ' filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
- ' ' Reset Start Drive/Path
- ' ChDrive (Left(.DefaultFilePath, 1))
- ' ChDir (.DefaultFilePath)
- 'End With
- '' Exit on Cancel
- '
- 'If Not IsArray(filename) Then
- ' MsgBox "Nenhum arquivo selecionado."
- ' Exit Function
- 'End If
- Windows(principal).Activate
- linha = 1
- 'rs.Close
- For i = 0 To UBound(ultima_milha)
- id_circuito = 0
- id_er = 0
- id_slot = 0
- id_porta = 0
- select_circuito = "select id_circuito from circuito where upper(dsc_designacao) = upper('" & ultima_milha(i).circuito & "')"
- rs.Open select_circuito, conn
- If rs.BOF = False Then
- id_circuito = rs!id_circuito
- Range("A" & linha).Value = ultima_milha(i).circuito
- Range("B" & linha).Value = id_circuito
- Else
- Range("A" & linha).Value = ultima_milha(i).circuito
- Range("B" & linha).Value = "NE"
- End If
- rs.Close
- If id_circuito <> 0 Then
- select_er = "select id_planejavel from elemento_rede where upper(sgl_elemento) = '" & UCase(ultima_milha(i).mux) & "'"
- rs.Open select_er, conn
- If rs.BOF = False Then
- id_er = rs!id_planejavel
- Range("C" & linha).Value = ultima_milha(i).mux
- Range("D" & linha).Value = id_er
- Else
- Range("C" & linha).Value = ultima_milha(i).mux
- Range("D" & linha).Value = "NE"
- End If
- rs.Close
- If id_er <> 0 Then
- slot_teste1 = ultima_milha(i).mux & "." & ultima_milha(i).slot_mux
- slot_teste1 = UCase(slot_teste1)
- select_slot = "select id_planejavel from slot_er where upper(sgl_elemento) = '" & slot_teste1 & "'"
- rs.Open select_slot, conn
- If rs.BOF = False Then
- id_slot = rs!id_planejavel
- Range("E" & linha).Value = ultima_milha(i).slot_mux
- Range("F" & linha).Value = id_slot
- Else
- Range("E" & linha).Value = ultima_milha(i).slot_mux
- Range("F" & linha).Value = "NE"
- End If
- rs.Close
- If id_slot = 0 Then
- If Len(ultima_milha(i).slot_mux) <= 3 Then
- If InStr(1, UCase(ultima_milha(i).slot_mux), "S") <> 0 Then
- slot_teste2 = ultima_milha(i).mux & "." & Mid(ultima_milha(i).slot_mux, InStr(1, UCase(ultima_milha(i).slot_mux), "S") + 1)
- slot_teste2 = UCase(slot_teste2)
- select_slot = "select id_planejavel from slot_er where upper(sgl_elemento) = '" & slot_teste2 & "'"
- rs.Open select_slot, conn
- If rs.BOF = False Then
- id_slot = rs!id_planejavel
- Range("E" & linha).Value = ultima_milha(i).slot_mux
- Range("F" & linha).Value = id_slot
- Else
- Range("E" & linha).Value = ultima_milha(i).slot_mux
- Range("F" & linha).Value = "NE"
- End If 'If rs.BOF = False Then
- rs.Close
- End If 'If InStr(1, UCase(ultima_milha(i).slot_mux), "S") <> 0 Then
- End If ' If Len(ultima_milha(i).slot_mux) <= 3 Then
- End If
- If id_slot = 0 Then
- select_porta = "select pe.id_porta_er as id_porta_er from porta_er pe, porta p where p.id_porta = pe.id_porta and pe.id_elemento_rede = " & id_er & " and p.dsc_designacao = '" & ultima_milha(i).porta_mux & "'"
- rs.Open select_porta, conn
- If rs.BOF = False Then
- id_porta = rs!id_porta_er
- Range("G" & linha).Value = ultima_milha(i).porta_mux
- Range("H" & linha).Value = id_porta
- Else
- Range("G" & linha).Value = ultima_milha(i).porta_mux
- Range("H" & linha).Value = "NE"
- End If
- rs.Close
- If id_porta = 0 Then
- If Len(ultima_milha(i).porta_mux) <= 3 Then
- If InStr(1, UCase(ultima_milha(i).porta_mux), "P") <> 0 Then
- porta_teste = Mid(1, InStr(1, UCase(ultima_milha(i).porta_mux), "P") + 1)
- porta_teste = UCase(porta_teste)
- select_porta = "select pe.id_porta_er as id_porta_er from porta_er pe, porta p where p.id_porta = pe.id_porta and pe.id_elemento_rede = " & id_er & " and p.dsc_designacao = '" & porta_teste & "'"
- rs.Open select_porta, conn
- If rs.BOF = False Then
- id_porta = rs!id_porta_er
- Range("G" & linha).Value = ultima_milha(i).porta_mux
- Range("H" & linha).Value = id_porta
- Else
- Range("G" & linha).Value = ultima_milha(i).porta_mux
- Range("H" & linha).Value = "NE"
- End If
- rs.Close
- End If 'If InStr(1, UCase(ultima_milha(i).slot_mux), "S") <> 0 Then
- End If ' If Len(ultima_milha(i).slot_mux) <= 3 Then
- End If
- Else
- select_porta = "select pe.id_porta_er as id_porta_er from porta_er pe, porta p where p.id_porta = pe.id_porta and pe.id_slot = " & id_slot & " and pe.id_elemento_rede = " & id_er & " and p.dsc_designacao = '" & ultima_milha(i).porta_mux & "'"
- rs.Open select_porta, conn
- If rs.BOF = False Then
- id_porta = rs!id_porta_er
- Range("G" & linha).Value = ultima_milha(i).porta_mux
- Range("H" & linha).Value = id_porta
- Else
- Range("G" & linha).Value = ultima_milha(i).porta_mux
- Range("H" & linha).Value = "NE"
- End If
- rs.Close
- If id_porta = 0 Then
- If Len(ultima_milha(i).porta_mux) <= 3 Then
- If InStr(1, UCase(ultima_milha(i).porta_mux), "P") <> 0 Then
- porta_teste = Mid(ultima_milha(i).porta_mux, InStr(1, UCase(ultima_milha(i).porta_mux), "P") + 1)
- porta_teste = UCase(porta_teste)
- select_porta = "select pe.id_porta_er as id_porta_er from porta_er pe, porta p where p.id_porta = pe.id_porta and pe.id_slot = " & id_slot & " and pe.id_elemento_rede = " & id_er & " and p.dsc_designacao = '" & porta_teste & "'"
- rs.Open select_porta, conn
- If rs.BOF = False Then
- id_porta = rs!id_porta_er
- Range("G" & linha).Value = ultima_milha(i).porta_mux
- Range("H" & linha).Value = id_porta
- Else
- Range("G" & linha).Value = ultima_milha(i).porta_mux
- Range("H" & linha).Value = "NE"
- End If
- rs.Close
- End If 'If InStr(1, UCase(ultima_milha(i).slot_mux), "S") <> 0 Then
- End If ' If Len(ultima_milha(i).slot_mux) <= 3 Then
- End If
- End If ' if id_slot = 0 then
- If id_porta <> 0 Then
- select_porta_circ = "select * from circuito where id_porta_origem = " & id_porta
- rs.Open select_porta_circ, conn
- If rs.BOF = False Then
- Range("I" & linha).Value = "Porta Origem Encontrada"
- Else
- rs.Close
- select_porta_circ = "select * from circuito where id_porta_destino = " & id_porta
- rs.Open select_porta_circ, conn
- If rs.BOF = False Then
- Range("I" & linha).Value = "Porta Destino Encontrada"
- Else
- Range("I" & linha).Value = "Circuito sem portas no SICOP"
- End If
- rs.Close
- End If 'If rs.BOF = False Then
- End If 'If id_porta <> 0 Then
- End If 'If id_er <> 0 Then
- End If 'If id_circuito <> 0 Then
- linha = linha + 1
- Next
- compara_eng_com = nova
- End Function
- Public Function arruma(ByVal texto As String) As String
- arruma = RemoveSpaces(UCase(texto))
- End Function
- Public Function RemoveSpaces(ByVal strInput As String)
- ' Removes all spaces from a string of text
- Test:
- If InStr(strInput, " ") = 0 Then
- RemoveSpaces = strInput
- Else
- strInput = Left(strInput, InStr(strInput, " ") - 1) _
- & Right(strInput, Len(strInput) - InStr(strInput, " "))
- GoTo Test
- End If
- End Function
- Public Function erro(ByVal arq_erro As String, ByVal origem As String, ByVal endereco As String, ByVal subend As String, ByVal valor As String, ByVal dsc_erro As String) As Integer
- If valor = "" Then
- valor = "Erro"
- End If
- Windows(arq_erro).Activate
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- Range("A" & LastRow + 1).Select
- If endereco <> "" And subend <> "" And valor <> "" Then
- ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=endereco, SubAddress:=subend, TextToDisplay:=valor
- Else
- Range("A" & LastRow + 1).Value = "Erro"
- End If
- Range("B" & LastRow + 1).Value = dsc_erro
- Windows(origem).Activate
- erro = 0
- End Function
- Public Function create_folder(ByRef MyPath As String)
- Dim FSO As New FileSystemObject
- FSO.CreateFolder MyPath
- End Function
- Public Function FileFolderExists(ByRef strFullPath As String) As Boolean
- 'Author : Ken Puls (www.excelguru.ca)
- 'Macro Purpose: Check if a file or folder exists
- On Error GoTo EarlyExit
- If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
- EarlyExit:
- On Error GoTo 0
- End Function
- Public Function Clear_All_Files_And_SubFolders_In_Folder(ByRef MyPath As String)
- 'Delete all files and subfolders
- 'Be sure that no file is open in the folder
- Dim FSO As Object
- 'Dim MyPath As String
- Set FSO = CreateObject("scripting.filesystemobject")
- 'MyPath = "C:\Users\a\Test" '<< Change
- If Right(MyPath, 1) = "\" Then
- MyPath = Left(MyPath, Len(MyPath) - 1)
- End If
- If FSO.FolderExists(MyPath) = False Then
- MsgBox MyPath & " doesn't exist"
- Exit Function
- End If
- On Error Resume Next
- 'Delete files
- FSO.DeleteFile MyPath & "\*.*", True
- 'Delete subfolders
- FSO.DeleteFolder MyPath & "\*.*", True
- On Error GoTo 0
- End Function
- Public Function GetSpecialFolderPaths()
- Dim WSHShell As Object
- Dim strPath As String
- Dim strFolderName As String
- Dim intLoop As Integer
- Set WSHShell = CreateObject("Wscript.Shell")
- For intLoop = 0 To WSHShell.SpecialFolders.Count - 1
- strPath = WSHShell.SpecialFolders(intLoop)
- strFolderName = Mid(strPath, InStrRev(strPath, Application.PathSeparator) + 1, 9999)
- If strFolderName = "Roaming" Then
- GetSpecialFolderPaths = strPath
- Exit Function
- End If
- Next intLoop
- Set WSHShell = Nothing
- End Function
- Public Function Copy_Folder(ByRef FromPath As String, ByRef ToPath As String) As String
- Dim FSO As Object
- 'Dim FromPath As String
- 'Dim ToPath As String
- ' ToPath = ToPath & Format(Now, "yyyy-mm-dd h-mm-ss")
- If Right(FromPath, 1) = "\" Then
- FromPath = Left(FromPath, Len(FromPath) - 1)
- End If
- If Right(ToPath, 1) = "\" Then
- ToPath = Left(ToPath, Len(ToPath) - 1)
- End If
- Set FSO = CreateObject("scripting.filesystemobject")
- If FSO.FolderExists(FromPath) = False Then
- Exit Function
- End If
- FSO.CopyFolder Source:=FromPath, Destination:=ToPath
- 'Copy_Folder FromPath
- End Function
- Public Function UsedRange_Example_Column()
- Dim LastColumn As Long
- With ActiveSheet.UsedRange
- LastColumn = .Columns(.Columns.Count).Column
- End With
- UsedRange_Example_Column = LastColumn
- End Function
- Public Function Copy_One_File(ByRef arq_origem As String, ByRef pasta_destino As String)
- Dim FSO As New FileSystemObject
- FSO.CopyFile arq_origem, pasta_destino, True
- 'Copy_One_File = "ok"
- End Function
- Public Function xlCellTypeLastCell_Example_Row()
- Dim LastRow As Long
- With ActiveSheet
- LastRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
- End With
- xlCellTypeLastCell_Example_Row = LastRow
- End Function
- Public Function ultimamilha(ByRef Filename() As Variant, ByRef tabelao As String) As String
- 'CRIA A CONEXAO COM O BANCO
- Set rs = New ADODB.Recordset
- ConnectDB
- rs.ActiveConnection = conexao
- rs.LockType = adLockOptimistic
- rs.CursorLocation = adUseClient
- rs.CursorType = adOpenDynamic
- 'DECLARACAO DE VARIAVEIS
- Dim sheet As Worksheet
- Dim celula, celula1 As Range
- Dim LastRow As Long
- Dim Filter As String
- Dim FilterIndex As Integer
- ' Dim filename As Variant
- Dim remove As String
- Dim i As Integer
- ReDim Preserve ciclo(0)
- ReDim Preserve ciclo_pop(0)
- ReDim Preserve mux(0)
- ReDim Preserve ciclo_placa(0)
- Dim modens() As modens
- Dim placas() As placas
- Dim portas() As portas
- Dim tipo_modem() As tipo_modem
- ReDim Preserve modens(0)
- ReDim Preserve tipo_modem(0)
- ReDim Preserve placas(0)
- ReDim Preserve portas(0)
- Dim m As Integer
- Dim n As Integer
- rodada = 0
- 'NAO ATUALIZA A TELA
- 'Application.ScreenUpdating = False
- profile_folder = GetSpecialFolderPaths()
- operadora_caminho = profile_folder & "\SICOP\Auxiliar\operadoras.xlsx"
- Workbooks.Open operadora_caminho, False
- hierarquias_caminho = profile_folder & "\SICOP\Auxiliar\hierarquias.xlsx"
- Workbooks.Open hierarquias_caminho, False
- ' ' File filters
- ' Filter = "Excel Files (*.xls),*.xls," & _
- ' "Text Files (*.txt),*.txt," & _
- ' "All Files (*.*),*.*"
- ' ' Default filter to *.*
- ' FilterIndex = 3
- ' ' Set Dialog Caption
- ' Title = "Escolha o arquivo de circuitos "
- ' ' Select Start Drive & Path
- ' ChDrive ("C")
- ' ChDir ("C:\Users\acunha\Desktop\Trabalho\Engenharia\Facilidades\")
- ' With Application
- ' ' Set File Name Array to selected Files (allow multiple)
- ' filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
- ' ' Reset Start Drive/Path
- ' ChDrive (Left(.DefaultFilePath, 1))
- ' ChDir (.DefaultFilePath)
- ' End With
- ' ' Exit on Cancel
- '
- ' If Not IsArray(filename) Then
- ' MsgBox "Nenhum arquivo selecionado."
- ' Exit Function
- ' End If
- 'CRIA 1 NOVA PLANILHA
- principal = ActiveWorkbook.Name
- Workbooks.Add
- ActiveWorkbook.Activate
- nova = ActiveWorkbook.Name
- Windows(nova).Activate
- Cells.Select
- Selection.NumberFormat = "@"
- Range("A1").Select
- 'Workbooks.Add
- 'ActiveWorkbook.Activate
- 'plan_erro = ActiveWorkbook.Name
- Windows(principal).Activate
- 'LOOP DOS ARQUIVOS SELECIONADOS - CONTROLE DE FACILIDADES
- ' Open Files
- For sasa = LBound(Filename) To UBound(Filename) - 1 ' FOR abre arquivos
- msg = msg & Filename(sasa) & vbCrLf ' This can be removed
- 'filename(sasa) = profile_folder & "\SICOP\Facilidades\Controle\" & filename(sasa)
- Workbooks.Open Filename(sasa), False
- arquivo = ActiveWorkbook.Name
- Windows(arquivo).Activate
- If arquivo Like "*Interior*" Then
- caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Interior"
- Else
- caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Região_Metropolitana"
- End If
- end2 = (caminhoarquivo & "\" & arquivo)
- 'gera a planilha tabelao
- For Each sheet In ActiveWorkbook.Worksheets
- If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- aba = sheet.Name
- sheet.Select
- Windows(arquivo).Activate
- LastRow = xlCellTypeLastCell_Example_Row
- Windows(arquivo).Activate
- coluna = UsedRange_Example_Column
- LastColumn = ConvertToLetter(coluna)
- RangeSelect = "A1:" & LastColumn & LastRow
- Windows(arquivo).Activate
- Range(RangeSelect).Select
- Selection.Copy
- Windows(tabelao).Activate
- LastRow = xlCellTypeLastCell_Example_Row
- If LastRow = 1 Then
- Range("C" & LastRow).Select
- Else
- Range("C" & LastRow + 1).Select
- End If 'If LastRow = 1 Then
- ActiveSheet.Paste
- Cells.Select
- Selection.WrapText = False
- Cells.EntireColumn.AutoFit
- If LastRow = 1 Then
- old_lastrow = LastRow
- Else
- old_lastrow = LastRow + 1
- End If
- LastRow = xlCellTypeLastCell_Example_Row
- For Each celula In Range("C" & old_lastrow & ":C" & LastRow)
- linha = celula.Row
- Range("A" & linha).Value = arquivo
- Range("B" & linha).Value = aba
- If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- Range("C" & linha).Select
- subend = "'" & aba & "'!C" & linha
- insere_anchor = celula.Value
- If IsNumeric(insere_anchor) Then
- insere_anchor = "'" & celula.Value
- End If
- ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=end2, SubAddress:=subend, TextToDisplay:=insere_anchor
- End If 'If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- Next 'For Each celula In Range()
- Windows(arquivo).Activate
- End If
- Next 'For Each sheet In ActiveWorkbook.Worksheets
- Windows(arquivo).Activate
- 'caminhoarquivo = ActiveWorkbook.Path
- 'DEFINE O CAMINHO DO ARQUIVO PARA CRIAR HYPERLINKS
- 'TRATA CADA UMA DAS ABAS DAS PLANILHAS
- For Each sheet In ActiveWorkbook.Worksheets
- rpt = 0
- 'IGNORA TODAS AS PLANILHAS QUE TEM RPT NO NOME - PLANILHAS DE RÁDIO
- ' If sheet.Name Like "*RPT*" Then
- '
- ' rpt = 1
- '
- ' End If
- 'IGNORA AS PLANILHAS QUE NÃO SÃO ULTIMA MILHA
- If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" And rpt = 0 Then
- 'SELECIONA A ABA
- sheet.Select
- aba = sheet.Name
- 'TRATA AS PLANILHAS QUE NÃO SÃO VESPER
- If sheet.Name <> "Sites_Vesper" Then
- 'ARMAZENA O NOME DA PLANILHA
- aba1 = sheet.Name
- 'ENCONTRA A SIGLA DO POP NO BANCO DE DADOS MYSQL
- sigla_pop = acha_sigla_pop(aba1)
- End If 'If sheet.Name <> "Sites_Vesper" Then
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- 'RESETA AS VARIÁVEIS PARA CADA CICLO - UM CICLO NESSE CASO É O INTERVALO ENTRE AS LINHAS PRETAS, QUE REPRESENTAM UM ÚNICO EQUIPAMENTO
- 'O CICLO COMEÇA DA LINHA 4 PORQUE A LINHA 3 É A PRIMEIRA PRETA
- inicio = 4
- ReDim ciclo(0)
- ReDim ciclo_pop(0)
- ReDim mux(0)
- ReDim ciclo_placa(0)
- i = 0
- 'ADICIONA O NOME DO MULTIPLEXADOR AO ARRAY MUX
- mux(0) = Range("C3").Value
- 'AUMENTA O TAMANHO DO ARRAY MUX
- ReDim Preserve mux(UBound(mux) + 1)
- For Each celula In Range("C4:C" & LastRow)
- 'DEFINE OS RANGES DE CADA EQUIPAMENTO (LINHA PRETA) NA PLANILHA
- 'ISSO SIGNIFICA CRIAR UMA ESTRUTURA DE LOOP PARA DA INTERVALO ENTRE LINHAS PRETAS NA PLANILHA
- 'LINHA CORRENTE
- linha = celula.Row
- 'VERIFICA SE A LINHA É PRETA E CASO A PLANILHA SEJA A VESPER, UM NOVO POP É INICIADO
- If celula.Interior.ColorIndex = 1 And sheet.Name = "Sites_Vesper" Then
- aba1 = Range("G" & linha).Value
- sigla_pop = acha_sigla_pop(aba1)
- End If
- 'ENCONTRA A LINHA PRETA E DEFINE O FINAL DO "CICLO" DE UM EQUIPAMENTO
- If celula.Interior.ColorIndex = 1 Then
- fim = linha - 1
- 'ADICIONA O CICLO AO ARRAY CICLO PARA GERAR UMA CADEIA DE LOOPS PARA IDENTIFICAR AS PLACAS, MUXS E POPS (VESPER)
- ciclo(i) = "E" & inicio & ":E" & fim
- ciclo_pop(i) = "I" & inicio & ":I" & fim
- ciclo_placa(i) = "K" & inicio & ":K" & fim
- mux(i + 1) = RemoveSpaces(UCase(Range("C" & linha).Value))
- 'AUMENTA O TAMANHO DOS ARRAYS SEM PERDER OS DADOS
- ReDim Preserve ciclo(UBound(ciclo) + 1)
- ReDim Preserve ciclo_pop(UBound(ciclo_pop) + 1)
- ReDim Preserve mux(UBound(mux) + 1)
- ReDim Preserve ciclo_placa(UBound(ciclo_placa) + 1)
- i = i + 1
- 'REINICIA A VARIAVEL 'INICIO' PARA DAR CONTINUIDADE AO LOOP
- inicio = linha + 1
- End If 'If celula.Interior.ColorIndex = 1 Then
- Next ' For Each celula In Range("C4:C" & LastRow)
- 'APOS IDENTIFICAR TODOS OS CICLOS, FINALIZA COM A ULTIMA LINHA PREENCHIDA DO ARQUIVO
- fim = LastRow
- ciclo(i) = "E" & inicio & ":E" & fim
- ciclo_pop(i) = "I" & inicio & ":I" & fim
- ciclo_placa(i) = "K" & inicio & ":K" & fim
- 'ESSE CICLO PEGA AS INFORMACOES DE CADA PLACA (COLUNA K) PARA IDENTIFICA-LAS CORRETAMENTE
- For i = 0 To UBound(ciclo_placa)
- 'RENOMEIA AS PLACAS DE CADA RANGE
- For Each celula In Range(ciclo_placa(i))
- linha_h = celula.Row
- If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- 'PEGA O NOME DA PLACA
- placa = celula.Value
- placa = UCase(RemoveSpaces((placa)))
- 'ATUALIZA O OBJETO 'PLACAS' COM O NOME DA PLACA E UM SEQUENCIAL PARA IDENTIFICAR QUANTAS PLACAS DO MESMO TIPO EXISTEM NAQUELE EQUIPAMENTO
- For t = 0 To UBound(placas)
- 'PEGA A SEQUENCIA DE CADA PLACA REPETIDA
- If placa = placas(t).nome Then
- placas(t).seq = placas(t).seq + 1
- seq_placa = placas(t).seq
- GoTo encontrado_placa
- End If ' If placa = placas(t).nome Then
- Next ' For t = 0 To UBound(placa)
- 'SO SERA EXECUTADO SE NAO ACHAR PLACA
- 'CASO NÃO EXISTA NENHUMA OCORRENCIA DA PLACA NO OBJETO 'PLACAS', ADICIONA UM NOVO ITEM COM O NOME DA PLACA NOVA
- placas(UBound(placas)).nome = placa
- placas(UBound(placas)).seq = 1
- seq_placa = 1
- ReDim Preserve placas(UBound(placas) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR PLACA
- encontrado_placa:
- 'APOS A PLACA TER SIDO CRIADA OU IDENTIFICADA, CRIA UM NOME PARA A PLACA NOS MOLDES - TIPO_DA_PLACA.MUX_ONDE_SE_ENCONTRA.SEQUENCIAL
- nome_placa_mod = placa & "." & mux(i) & "." & seq_placa
- celula.Value = nome_placa_mod
- 'REINICIA O ARRAY DE PORTAS PARA IDENTICAR AS PORTAS DA PLACA ATUAL
- ReDim portas(0)
- End If ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- 'INICIA A VARIAVEL DAS PORTAS
- porta = ""
- 'VERIFICA SE A EXISTE UMA PORTA ASSOCIADA AQUELA PLACA E SE A CELULA NAO ESTA VAZIA
- If Not IsEmpty(celula.Next.Next.Value) And RemoveSpaces((celula.Next.Next.Value)) <> "" Then
- 'ASSOCIA A PORTA A VARIAVEL
- porta = celula.Next.Next.Value
- porta = UCase(RemoveSpaces((porta)))
- End If
- If porta <> "" Then
- 'PEGA AS PORTAS DA PLACA
- 'ASSOCIA CADA PORTA DAQUELA PLACA AO OBJETO 'PORTAS'
- For t = 0 To UBound(portas)
- If porta = portas(t).nome Then
- portas(t).seq = portas(t).seq + 1
- seq_porta = portas(t).seq
- GoTo achou_porta
- End If
- Next
- 'CASO A PORTA NAO EXISTA, CRIA UMA NOVA ENTRADA
- 'SO SERA EXECUTADO SE NAO ACHAR PORTA
- portas(UBound(portas)).nome = porta
- portas(UBound(portas)).seq = 1
- seq_porta = 1
- ReDim Preserve portas(UBound(portas) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR PORTA
- achou_porta:
- 'CRIA UM IDENTIFICADOR PARA A PORTA NO FORMATO PORTA.SEQUENCIAL
- 'CASO NAO EXISTA A LETRA P NO CAMPO ADICIONA ESSA LETRA AO NOME DA PORTA E GRAVA NA CELULA DA PORTA
- If InStr(1, porta, "P") = 0 Then
- celula.Next.Next.Value = "'" & porta & "." & seq_porta
- Else
- celula.Next.Next.Value = porta & "." & seq_porta
- End If
- 'VARIAVEL PARA VERIFICACAO SE A PORTA ESTA COM A CELULA HACHURADA
- porta_hachurada = celula.Next.Next.Value
- hachu_seq = 1
- End If 'If porta <> "" Then
- 'IF PARA VERIFICAR SE A PORTA ESTA HACHURADA. CASO ESTEJA, E A CELULA ESTEJA VAZIA, PREENCHE O DADO COM A ULTIMA PORTA ENCONTRADA
- If IsEmpty(Range("M" & linha_h)) And RemoveSpaces(Range("M" & linha_h).Value) = "" And (Range("M" & linha_h).Interior.Pattern = 14 Or Range("M" & linha_h).Interior.Pattern = -4162) And Not IsEmpty(Range("C" & linha_h)) And RemoveSpaces(Range("C" & linha_h).Value) <> "" Then
- Range("M" & linha_h).Value = porta_hachurada & "." & hachu_seq
- hachu_seq = hachu_seq + 1
- End If
- Next ' For Each celula In Range(ciclo_placa(i))
- 'REINICIA O ARRAY DE PLACAS
- ReDim placas(0)
- Next ' For i = 0 To UBound(ciclo_placa)
- 'LOOP PARA IDENTIFICAR OS MODENS DO LADO DO POP - COLUNA E
- For i = 0 To UBound(ciclo) 'COLUNA E
- For Each celula In Range(ciclo(i))
- linha = celula.Row
- 'VERIFICA SE A CELULA ESA VAZIA, SE ESTIVER, 'RESETA' OS DADOS DA CELULA. ISSO PRECISA SER FEITO PORQUE MUITAS VEZES A FORMATACAO CONDICIONAL
- 'SOBREPOE OS DADOS REAIS DA CELULA. EX. UMA CELULA ESTÁ COM FUNDO PRETO, MAS DECIDO A FORMATACAO CONDICIONAL ESSE ITEM APARECE BRANCO/VERDE/AMARELO/LARANJA
- If IsEmpty(celula.Value) And RemoveSpaces((celula.Value)) = "" Then
- Range("E" & linha).Select
- Selection.Clear
- ' Range("E" & linha).Font.Bold = False
- End If
- 'FAZ A MESMA VERIFICACAO ACIMA, MAS PARA A PORTA
- If IsEmpty(celula.Next.Value) And RemoveSpaces((celula.Next.Value)) = "" Then
- Range("F" & linha).Select
- Selection.Clear
- ' Range("F" & linha).Font.Bold = False
- End If
- Next 'For Each celula In Range(ciclo(i))
- For Each celula In Range(ciclo(i))
- linha = celula.Row
- 'VERIFICAR SE AMBAS AS CELULAS DA COLUNA 'E' E 'F' NAO ESTAO VAZIAS
- If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And Not IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) <> "" And Range("F" & linha).Font.Color <> Range("E" & linha).Font.Color Then
- 'VERIFICA SE A COR DA FONTE DO EQUIPAMENTO É DIFERENTE DA COR DA PORTA DAQUELE EQUIPAMENTO
- If Range("E" & linha).Font.Color <> 0 And Range("F" & linha).Font.Color = 0 Then
- 'EM CASO POSITIVO, COPIA A COR DA FONTE DO EQUIPAMENTO PARA SUA RESPECTIVA PORTA
- Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
- 'FAZ A VERIFICACAO CONTRARIA - COR DA PORTA = COR DO EQUIPAMENTO
- ElseIf Range("F" & linha).Font.Color <> 0 And Range("E" & linha).Font.Color = 0 Then
- Range("E" & linha).Font.Color = Range("F" & linha).Font.Color
- End If
- End If
- 'VERIFICA SE HÁ UM CIRCUITO ASSOCIADO AQUELE EQUIPAMENTO E SE O EQUIPAMENTO E A PORTA EXISTEM
- If Not IsEmpty(Range("C" & linha).Value) And RemoveSpaces((Range("C" & linha).Value)) <> "" And IsEmpty(Range("E" & linha).Value) And RemoveSpaces((Range("E" & linha).Value)) = "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces((Range("F" & linha).Value)) = "" Then
- 'CASO NAO EXISTA EQUIPAMENTO, É CRIADO O EQUIPAMENTO 'CABO' COM SUA RESPECTIVA PORTA 'PO1'
- Range("E" & linha).Value = "CABO"
- Range("E" & linha).Font.Color = 0
- Range("F" & linha).Value = "PO1"
- Range("F" & linha).Font.Color = 0
- End If
- 'VERIFICA SE EXISTE UM EQUIPAMENTO MAS NAO EXISTE UMA PORTA ASSOCIADA A ELE
- If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" Then
- 'CASO O EQUIPAMENTO SEJA UM ASGA, ADICIONA A PORTA P1 PARA ELE
- If InStr(1, Range("E" & linha).Value, "ASGA") <> 0 Then
- Range("F" & linha).Value = "P1"
- Else
- 'SE NAO FOR UM EQUIPAMENTO ASGA, CRIA A PORTA ESPECIAL 1 - PE1
- Range("F" & linha).Value = "PE1"
- End If
- 'COLOCA A COR DA PORTA IGUAL A DO EQUIPAMENTO
- Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
- End If
- 'NAO SEI PRA QUE ESSE CODIGO ABAIXO FOI COMENTADO.
- ' If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" Then
- '
- ' Range("F" & linha).Value = "PE1"
- ' Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
- '
- ' End If
- 'VERIFICA SE EXISTE O EQUIPAMENTO, SE A PORTA E A PORTA ESTÁ VAZIA E SE O EQUIPAMENTO É UM DM706
- If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" And UCase(Range("E" & linha).Value) = "DM706" Then
- 'CASO SEJA, ADICIONA A PORTA P1 E REPETE A COR PARA O EQUIPAMENTO E PORTA
- Range("F" & linha).Value = "P1"
- Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
- End If
- 'CASO SEJA IDENTIFICADO O ITEM 'CPU64' NA COLUNA I, REMOVE ELE - NAO SERVE PARA NADA
- If RemoveSpaces(UCase(Range("I" & linha).Value)) = "CPU64" Then
- Range("I" & linha).Select
- Selection.Clear
- End If
- 'VERIFICA SE A CELULA DO EQUIPAMENTO NAO ESTA VAZIA
- If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- 'ASSOCIA O EQUIPAMENTO A VARIAVEL MODEM
- modem = UCase(RemoveSpaces(celula.Value))
- 'CASO O EQUIPAMENTO SEJA UM CABO, MUDA O NOME PARA CABO_CLI
- If modem = "CABO" Then
- modem = "CABO_CLI"
- End If
- 'ASSOCIA O NOME DO MODEM AO OBJETO-ARRAY MODENS
- modens(UBound(modens)).nome = modem
- 'SE O EQUIPAMENTO NAO FOR UM CABO, ADICIONA A COR DA FONTE AO OBJETO-ARRAY
- If modem <> "CABO" Then
- modens(UBound(modens)).cor_fonte = celula.Font.Color
- 'EM CASO CONTRARIO, SETA A COR COMO 'AUTOMATICO'
- Else
- modens(UBound(modens)).cor_fonte = 0
- End If
- 'ADICIONA A LINHA DE ONDE AQUELE MODEM VEIO
- modens(UBound(modens)).linha = celula.Row
- 'VERIFICA SE JÁ EXISTE O TIPO DE MODEM NA BASE, EM CASO NEGATIVO, CRIA O MODEM. EM CASO POSITIVO ADICIONA UM SEQUENCIAL PARA DIFERENCIACAO
- For t = 0 To UBound(tipo_modem)
- If tipo_modem(t).nome = modem Then
- GoTo encontrado_tipo_modem
- End If
- Next 'For t = 0 To UBound(tipo_modem)
- 'SO SERA EXECUTADO SE NAO ACHAR
- tipo_modem(UBound(tipo_modem)).nome = modem
- tipo_modem(UBound(tipo_modem)).seq = 1
- ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR
- encontrado_tipo_modem:
- 'AUMENTA O TAMANHO DO ARRAY
- ReDim Preserve modens(UBound(modens) + 1)
- End If ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- Next 'For Each celula In Range(ciclo(i))
- 'FORMATA O TIPO DO MODEM E SUA COR PARA SER INSERIDO NA CELULA
- For K = 0 To (UBound(modens) - 1)
- nome_modem = modens(K).nome
- cor_fonte_modem = modens(K).cor_fonte
- For u = 0 To (UBound(tipo_modem) - 1)
- If tipo_modem(u).nome = nome_modem Then
- seq_modem = tipo_modem(u).seq
- posicao_seq_modem = u
- Exit For
- End If 'If tipo_modem(u).nome = nome_modem Then
- Next 'For u = 0 To (UBound(tipo_modem) - 1)
- 'IDENTIFICA A SIGLA DO CLIENTE A PARTIR DA DESIGNACAO PARA COMPOR O NOME DO MODEM
- circuito_cliente = Range("C" & modens(K).linha).Value
- sigla_cliente = ""
- sigla_cliente = detecta(circuito_cliente, arquivo, mux(i))
- If sigla_cliente = "" Then
- sigla_cliente = mux(i)
- End If
- 'GERA O NOME DO MODEM PARA ALTERAR A CELULA
- nome_modem_mod = nome_modem & "." & sigla_cliente & "." & seq_modem
- 'CASO A COR SEJA AUTOMATICA (0) O MODEM SERÁ INSERIDO COM O SEQUENCIAL '1'. SENDO ASSIM PULA A ETAPA DE IDENTIFICAR A COR E SEQUENCIAL DO MODEM (LOGO ABAIX0)
- If cor_fonte_modem = 0 Then
- modens(K).novo_nome = nome_modem_mod
- tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
- GoTo linha_zero
- End If 'If cor_fonte_modem = 0 Then
- 'IDENTIFICA SE JÁ EXISTE O MODEM PELA COR DA FONTE, CASO EXISTA, PEGA O NOME DELE
- For y = 0 To (UBound(modens) - 1)
- If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
- modens(y).novo_nome = nome_modem_mod
- End If 'If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
- Next 'For y = 0 To (UBound(modens) - 1)
- 'ATUALIZA O SEQUENCIAL DO TIPO DO MODEM
- tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
- linha_zero:
- 'ATUALIZA O VALOR DA LINHA DO MODEM
- Range("E" & modens(K).linha).Value = nome_modem_mod
- Range("E" & modens(K).linha).Font.Color = Range("F" & modens(K).linha).Font.Color
- 'CASO O MODEM SEJA CABO_CLI, CRIA A PORTA OTICA 1 - 'PO1'
- If tipo_modem(posicao_seq_modem).nome = "CABO_CLI" Then
- Range("E" & modens(K).linha).Next.Value = "PO1"
- End If 'If tipo_modem(posicao_seq_modem).nome = "CABO" Then
- Next ' For k = 0 To UBound(modens)
- For Each celula In Range(ciclo(i))
- 'LOOP PARA IDENTIFICAR QUAIS MODENS TEM COR DIFERENTE DA AUTOMATICA E SUAS PORTAS ASSOCIADAS
- 'COLOCA AS CORES DAS PORTAS NOS MODENS!!! (LADO CLIENTE)
- 'VERIFICA SE A COR É DIFERENTE DE 0
- If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
- porta_cliente = celula.Next.Value
- cor_porta_cliente = celula.Next.Font.Color
- cor_encontrada = 0
- 'PROCURA PELA COR NO ARRAY MODENS
- For K = 0 To (UBound(modens) - 1)
- 'CASO ENCONTRE, ASSOCIA O EQUIPAMENTO DA MESMA COR À PORTA ASSOCIADA A ELE
- If modens(K).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
- celula.Value = modens(K).novo_nome
- ' celula.Font.Color = modens(k).cor_fonte
- End If 'If modens(k).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
- Next 'For k = 0 To (UBound(modens) - 1)
- 'IF DE VERIFICACAO DEBUG
- ' If IsEmpty(celula) And RemoveSpaces(celula.Value) = "" Then
- '
- ' laleq1a = 0
- '
- ' End If
- End If 'If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
- Next 'Each celula In Range(ciclo(i))
- 'REINICIA OS MODENS E TIPOS DE MODENS PARA O PROXIMO MULTIPLEXADOR
- ReDim modens(0)
- ReDim tipo_modem(0)
- Next 'For i = 0 To UBound(ciclo)
- For i = 0 To UBound(ciclo_pop) 'CICLO MODENS LADO POP COLUNA I
- 'LOOP QUE FAZ AS MESMAS COISAS DO LOOP ANTERIOR, SÓ QUE DESSA VEZ DO LADO DO CLIENTE, COLUNA I
- For Each celula In Range(ciclo(i))
- linha = celula.Row
- If IsEmpty(celula.Value) And RemoveSpaces((celula.Value)) = "" Then
- Range("I" & linha).Font.Color = 0
- Range("I" & linha).Font.Bold = False
- End If
- If IsEmpty(celula.Next.Value) And RemoveSpaces((celula.Next.Value)) = "" Then
- Range("J" & linha).Font.Color = 0
- Range("J" & linha).Font.Bold = False
- End If
- Next
- For Each celula In Range(ciclo_pop(i))
- linha = celula.Row
- If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- modem = UCase(RemoveSpaces(celula.Value))
- modens(UBound(modens)).nome = modem
- modens(UBound(modens)).cor_fonte = celula.Font.Color
- modens(UBound(modens)).linha = celula.Row
- If modem <> "CPU64" Then
- For t = 0 To UBound(tipo_modem)
- If tipo_modem(t).nome = modem Then
- GoTo encontrado_tipo_modem_pop
- End If
- Next 'For t = 0 To UBound(tipo_modem)
- 'SO SERA EXECUTADO SE NAO ACHAR
- tipo_modem(UBound(tipo_modem)).nome = modem
- tipo_modem(UBound(tipo_modem)).seq = 1
- ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR
- encontrado_tipo_modem_pop:
- ReDim Preserve modens(UBound(modens) + 1)
- End If 'If modem <> "CPU64" Then
- End If ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- Next 'For Each celula In Range(ciclo_pop(i))
- For K = 0 To (UBound(modens) - 1)
- nome_modem = modens(K).nome
- cor_fonte_modem = modens(K).cor_fonte
- For u = 0 To (UBound(tipo_modem) - 1)
- If tipo_modem(u).nome = nome_modem Then
- seq_modem = tipo_modem(u).seq
- posicao_seq_modem = u
- Exit For
- End If 'If tipo_modem(u).nome = nome_modem Then
- Next 'For u = 0 To (UBound(tipo_modem) - 1)
- 'VERIFICA SE O MODEM É UM MOFL4E1, AS PORTAS DELE SAO TRATADAS DE FORMA DIFERENTE
- If nome_modem = "MOFL4E1" Then
- seq_modem = Mid(Range("J" & modens(K).linha).Value, 1, 1)
- End If
- If nome_modem <> "DM705" Then
- nome_modem_mod = nome_modem & "." & mux(i) & "." & seq_modem
- Else
- mod_dm705 = ""
- For Each dm In Range("G" & linha & ":G" & LastRow)
- nome_dm = dm.Value
- nome_dm = UCase(nome_dm)
- If dm.Interior.ColorIndex = 1 Then
- If InStr(1, nome_dm, "P/") <> 0 And InStr(1, nome_dm, "(") <> 0 And InStr(1, nome_dm, ")") <> 0 Then
- mod_dm705 = Trim(Range("C" & dm.Row).Value)
- Exit For
- 'seek_sigla1 = Mid(nome_dm, InStrRev(nome_dm, "P/") + 2, Len(nome_dm))
- 'seek_sigla2 = Mid(seek_sigla1, 1, Len(seek_sigla1) - 1)
- End If
- End If
- Next
- If mod_dm705 <> "" Then
- nome_modem_mod = nome_modem & "." & mod_dm705 & "." & seq_modem
- Else
- nome_modem_mod = nome_modem & "." & mux(i) & "." & seq_modem
- End If
- End If
- If cor_fonte_modem = 0 Then
- modens(K).novo_nome = nome_modem_mod
- tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
- GoTo linha_zero_pop
- End If 'If cor_fonte_modem = 0 Then
- For y = 0 To (UBound(modens) - 1)
- If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
- modens(y).novo_nome = nome_modem_mod
- End If 'If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
- Next 'For y = 0 To (UBound(modens) - 1)
- tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
- linha_zero_pop:
- Range("I" & modens(K).linha).Value = nome_modem_mod
- Range("I" & modens(K).linha).Font.Color = Range("J" & modens(K).linha).Font.Color
- 'CASO O MODEM SEJA UM CABO_POP, CRIA UMA PORTA OTICA 1 PARA ELE PO1
- If tipo_modem(posicao_seq_modem).nome = "CABO_POP" Then
- Range("I" & modens(K).linha).Next.Value = "PO1"
- End If 'If tipo_modem(posicao_seq_modem).nome = "CABO" Then
- Next ' For k = 0 To UBound(modens)
- For Each celula In Range(ciclo_pop(i))
- linha_plan = celula.Row
- 'VERIFICA SE A LINHA ACIMA DA LINHA ATUAL É PRETA E SE A PLANILHA É VESPER. EM CASO POSITIVO PEGA A SIGLA DO POP
- If Range("C" & linha_plan - 1).Interior.ColorIndex = 1 And sheet.Name = "Sites_Vesper" Then
- aba1 = Range("G" & linha_plan - 1).Value
- sigla_pop = acha_sigla_pop(aba1)
- End If
- 'PEGA OS DADOS DA CELULA PARA GERAR O HYPERLINK
- subend = ("'" & aba & "'!" & RemoveDolars(celula.Address))
- 'strcell = celula.Address
- linha_preta = 0
- 'RESETA AS VARIAVEIS QUE SAO UTILIZADAS QUANDO O MODEM É FLEX
- nome_flex = ""
- numero_flex = ""
- slot_flex = ""
- porta_flex = ""
- 'VERIFICA SE A PORTA ESTÁ PREENCHIDA, SE A COR DA FONTE É DIFERENTE DE 0 E SE NÃO EXISTEM OS CARACTERES ESPECIAIS '-' E '/' NA PORTA
- If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 And InStr(celula.Next.Value, "/") = 0 And InStr(celula.Next.Value, "-") = 0 Then
- 'PEGA OS DADOS DAS PORTAS DO EQUIPAMENTO DO CLIENTE
- porta_cliente = celula.Next.Value
- cor_porta_cliente = celula.Next.Font.Color
- 'VERIFICA SE A COR JÁ FOI UTILIZADA EM ALGUM MODEM ANTERIOR AO ATUAL
- For K = 0 To (UBound(modens) - 1)
- If modens(K).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
- celula.Value = modens(K).novo_nome
- End If 'If modens(k).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
- Next 'For k = 0 To (UBound(modens) - 1)
- 'CASO A PORTA TENHA '/' OU '-' ELA É DE UM MODEM FLEX
- ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") = 0 And countSeparators(celula.Next.Value, "/") < 2 Then
- 'SEPARA AS INFORMAÇÕES DA PORTA DO MODEM FLEX
- celula.Select
- celula.Next.Select
- celula.Next.Font.Color = 0
- nome_flex = "MOFL4E1"
- numero_flex = Mid(celula.Next.Value, 1, InStr(1, celula.Next.Value, "/") - 2)
- slot_flex = Mid(celula.Next.Value, 2, InStr(1, celula.Next.Value, "/") - 2)
- porta_flex = "P" & Mid(celula.Next.Value, InStr(1, celula.Next.Value, "/") + 1, Len(celula.Next.Value))
- celula.Value = nome_flex & "." & mux(i) & "." & numero_flex
- ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") <> 0 And countSeparators(celula.Next.Value, "/") < 2 Then
- 'CASO NAO SEJA UM MODEM FLEX, A PORTA É DE UM MODEM AX4E1
- celula.Next.Value = UCase(RemoveSpaces((celula.Next.Value)))
- celula.Next.Font.Color = 0
- nome_flex = "MOAX4E1"
- tira_mux = Mid(celula.Next.Value, InStr(1, celula.Next.Value, "-") + 1, Len(celula.Next.Value))
- numero_flex = Mid(tira_mux, 1, 1)
- tira_numero = Mid(tira_mux, InStr(1, tira_mux, "S"), Len(tira_mux))
- slot_flex = Mid(tira_numero, 1, InStr(1, tira_numero, "/") - 1)
- tira_slot = Mid(tira_numero, InStr(1, tira_numero, "/") + 1, Len(tira_numero))
- interface = Mid(tira_slot, 1, InStr(1, tira_slot, "P") - 1)
- slot_flex = slot_flex & "/" & interface
- porta_flex = Mid(tira_slot, InStr(1, tira_slot, interface) + 1, Len(tira_slot))
- celula.Value = nome_flex & "." & mux(i) & "." & numero_flex
- 'CASO A PORTA NAO SEJA NEM DE UM MODEM FLEX, NEM DE UM AX4E1, É DE UM MDOEM DM4E1S
- ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") = 0 And countSeparators(celula.Next.Value, "/") = 2 Then
- numero_dm4 = Mid(celula.Next.Value, 1, InStr(1, celula.Next.Value, "/") - 1)
- slot_porta = Mid(celula.Next.Value, InStr(1, celula.Next.Value, "/") + 1, Len(celula.Next.Value))
- celula.Value = "DM4E1S13." & mux(i) & "." & numero_dm4
- celula.Next.Value = "'" & slot_porta
- End If 'If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
- 'AUMENTA EM 1 A CONTAGEM DA LINHA PRETA PARA O PROXIMO LOOP
- If celula.Interior.ColorIndex = 1 Then
- linha_preta = linha_preta + 1
- End If
- If Not IsEmpty(Range("L" & linha_plan).Value) And RemoveSpaces(Range("L" & linha_plan).Value) <> "" Then
- 'PEGA O VALOR DA CELULA QUE CONTEM O SLOT
- slot_plan = Range("L" & linha_plan).Value
- End If
- If Not IsEmpty(Range("K" & linha_plan).Value) And RemoveSpaces(Range("K" & linha_plan).Value) <> "" Then
- 'PEGA O VALOR DA CELULA QUE CONTEM A PLACA
- placa_plan = Range("K" & linha_plan).Value
- End If
- 'VERIFICA SE EXISTE UM CIRCUITO EXISTE E ESTE NÃO ESTÁ VAZIO
- If Not IsEmpty(Range("C" & linha_plan).Value) And RemoveSpaces((Range("C" & linha_plan).Value)) <> "" Then
- circuito_plan = Range("C" & linha_plan).Value
- pop_mux_plan = sigla_pop
- nome_mux_plan = mux(i)
- tipo_mux_plan = acha_tipo_equip(nome_mux_plan)
- If tipo_mux_plan = "99" Then
- subend_erro = ("'" & aba & "'!" & RemoveDolars(celula.Address))
- ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, celula.Value, "Erro - Tipo de Multiplexador não identificado : " & nome_mux_plan)
- vazia = 1
- End If
- 'PEGA OS DADOS DA PORTA DO MUX - COLUNA M
- If Not IsEmpty(Range("M" & linha_plan).Value) And RemoveSpaces(Range("M" & linha_plan).Value) <> "" Then
- porta_mux_plan = Range("M" & linha_plan).Value
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("M" & linha_plan).Address))
- ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("M" & linha_plan).Value, "Porta do Multiplexador não encontrada.")
- vazia = 1
- End If
- 'PEGA OS DADOS DO MODEM DO LADO DO POP
- If Not IsEmpty(Range("I" & linha_plan).Value) And RemoveSpaces(Range("I" & linha_plan).Value) <> "" Then
- modem_pop_plan = Range("I" & linha_plan).Value
- tipo_modem_pop_plan = Mid(modem_pop_plan, 1, InStr(1, modem_pop_plan, ".") - 1)
- Else
- 'CASO ESTEJA VAZIO, CRIA-SE O CABO_POP
- modem_pop_plan = "CABO_POP"
- tipo_modem_pop_plan = "CABO_POP"
- 'VALIDA O TIPO DE MODEM DO LADO DO POP E CASO EXISTA, ADICIONA UM SEQUENCIAL A ELE
- For t = 0 To UBound(tipo_modem)
- If tipo_modem(t).nome = modem_pop_plan Then
- tipo_modem(t).seq = tipo_modem(t).seq + 1
- seq_modem_vazio = tipo_modem(t).seq
- GoTo encontrado_tipo_modem_pop_vazio
- End If
- Next 'For t = 0 To UBound(tipo_modem)
- 'SO SERA EXECUTADO SE NAO ACHAR
- 'CRIA UM NOVO TIPO DE MODEM CASO NENHUM SEJA ENCONTRADO
- tipo_modem(UBound(tipo_modem)).nome = modem_pop_plan
- tipo_modem(UBound(tipo_modem)).seq = 1
- seq_modem_vazio = 1
- ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR
- encontrado_tipo_modem_pop_vazio:
- modem_pop_plan = modem_pop_plan & "." & mux(i) & "." & seq_modem_vazio
- End If
- 'CASO O MODEM SEJA FLEX OU AX4E1, A PORTA DO MODEM DO CLIENTE É A VARIAVEL 'slot_flex' E A PORTA DO LADO DO POP É PO1
- If tipo_modem_pop_plan = "MOFL4E1" Or tipo_modem_pop_plan = "MOAX4E1" Then
- porta_modem_pop_cliente = slot_flex
- porta_modem_cliente_pop = "PO1"
- Else
- 'CASO CONTRARIO AMBAS AS PORTAS DO LADO DO CLIENTE E DO POP SÃO PORTAS OTICAS (PO1)
- porta_modem_pop_cliente = "PO1"
- porta_modem_cliente_pop = "PO1"
- End If
- 'CASO NAO EXISTA UMA PORTA DE MODEM FLEX E A COLUNA J (PORTA DO LADO DO POP) NAO ESTEJA VAZIA,
- If porta_flex = "" And Not IsEmpty(Range("J" & linha_plan).Value) And RemoveSpaces(Range("J" & linha_plan).Value) <> "" Then
- porta_pop_plan = Range("J" & linha_plan).Value
- 'CASO EXISTA UMA PORTA FLEX, PEGA-SE O VALOR DELA
- ElseIf porta_flex <> "" Then
- porta_pop_plan = porta_flex & "-" & slot_flex
- 'CASO O MODEM SEJA CABO_POP, CRIA-SE A PORTA 'PE1' E A PORTA 'PE1' para conversores
- ElseIf tipo_modem_pop_plan = "CABO_POP" Then
- porta_pop_plan = "PE1"
- ElseIf tipo_modem_pop_plan = "CONV" Then
- porta_pop_plan = "PE1"
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("F" & linha_plan).Address))
- ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("F" & linha_plan).Value, "Porta do não modem encontrada.")
- vazia = 1
- End If
- 'CASO O MODEM DO CLIENTE NAO ESTEJA VAZIO, PEGA OS DADOS DELE
- If Not IsEmpty(Range("E" & linha_plan).Value) And RemoveSpaces(Range("E" & linha_plan).Value) <> "" Then
- modem_cliente_plan = Range("E" & linha_plan).Value
- tipo_modem_cliente_plan = Mid(modem_cliente_plan, 1, InStr(1, modem_cliente_plan, ".") - 1)
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("E" & linha_plan).Address))
- ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("E" & linha_plan).Value, "Modem do cliente não encontrado.")
- vazia = 1
- End If
- 'CASO O MODEM DO CLIENTE EXISTA E A COLUNA F NAO ESTEJA VAZIA, PEGA-SE OS DADOS DA PORTA DO CLIENTE DA COLUNA F
- If Not IsEmpty(Range("E" & linha_plan).Value) And RemoveSpaces(Range("E" & linha_plan).Value) <> "" And Not IsEmpty(Range("F" & linha_plan).Value) And RemoveSpaces(Range("F" & linha_plan).Value) <> "" Then
- porta_cli_plan = Range("F" & linha_plan).Value
- 'CASO O MODEM SEJA CABO_CLI, CRIA-SE A PORTA 'P01' E A PORTA 'PE1' para conversores
- ElseIf tipo_modem_cliente_plan = "CABO_CLI" Then
- porta_cli_plan = "PO1"
- ElseIf tipo_modem_cliente_plan = "CONV" Then
- porta_cli_plan = "PE1"
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("F" & linha_plan).Address))
- ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("F" & linha_plan).Value, "Porta do não modem encontrada.")
- vazia = 1
- End If
- 'CASO A COLUNA N ESTEJA PREENCHIDA, PEGA-SE OS DADOS DA OPERADORA DELA
- If Not IsEmpty(Range("N" & linha_plan).Value) And RemoveSpaces(Range("N" & linha_plan).Value) <> "" Then
- operadora_plan = Range("N" & linha_plan).Value
- End If
- 'CASO A COLUNA O ESTEJA PREENCHIDA, PEGA-SE OS DADOS DA OS DELA
- If Not IsEmpty(Range("O" & linha_plan).Value) And RemoveSpaces(Range("O" & linha_plan).Value) <> "" Then
- os_plan = Range("O" & linha_plan).Value
- End If
- 'CASO A COLUNA B ESTEJA PREENCHIDA, PEGA-SE OS DADOS DO STATUS DO CIRCUITO DELA
- If Not IsEmpty(Range("B" & linha_plan)) And RemoveSpaces(Range("B" & linha_plan).Value) <> "" Then
- status_circuito = Range("B" & linha_plan).Value
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("B" & linha_plan).Address))
- ''retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("B" & linha_plan).Value, "Status do circuito não encontrado.")
- vazia = 1
- End If
- 'SELECIONA A PLANILHA CRIADA NO COMEÇO DO SCRIPT
- Windows(nova).Activate
- 'CALCULA A ULTIMA LINHA PREENCHIDA DELE
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow2 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- 'VARIAVEIS UTLIZADAS PRA CONTROLE DE LOOP NA PLANILHA NOVA
- If (LastRow2 = 0 Or LastRow2 = "") And rodada = 0 Then
- inicio_nova = 1
- rodada = 1
- ElseIf rodada = 0 Then
- inicio_nova = LastRow2
- rodada = 1
- End If
- 'PREENCHE OS DADOS OBTIDOS NO SCRIPT E TRANSCREVE-OS PARA A NOVA PLANILHA
- ' VALIDA SE EXISTEM PORTAS ORFAS COM O MESMO ENDEREÇO
- If modem_cliente_plan = "" Then
- Windows(arquivo).Activate
- porta_mod_cli = Range("F" & linha_plan).Value
- cor_porta_mod_cli = Range("F" & linha_plan).Font.Color
- end_mod_cli = Range("H" & linha_plan).Value
- end_mod_cli = RemoveSpaces(UCase(end_mod_cli))
- For Each celula_mod_cli In Range("C4:C" & LastRow)
- linha_mod_cli = celula_mod_cli.Row
- If (Range("F" & linha_mod_cli).Font.Color = cor_porta_mod_cli) And (end_mod_cli = RemoveSpaces(UCase(Range("H" & linha_mod_cli).Value))) And (linha_mod_cli <> linha_plan) Then
- modem_cliente_plan = Range("E" & linha_mod_cli).Value
- porta_cli_plan = porta_mod_cli
- tipo_modem_cliente_plan = Mid(modem_cliente_plan, 1, InStr(1, modem_cliente_plan, ".") - 1)
- Exit For
- End If
- Next 'For Each CELULA_MOD_CLI In Range("C4:C" & lastrow)
- Windows(nova).Activate
- End If
- 'If vazia = 0 Then
- Range("A" & LastRow2 + 1).Select
- ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=end2, SubAddress:=subend, TextToDisplay:=circuito_plan
- Range("B" & LastRow2 + 1).Value = pop_mux_plan
- Range("D" & LastRow2 + 1).Value = nome_mux_plan
- Range("C" & LastRow2 + 1).Value = tipo_mux_plan
- Range("E" & LastRow2 + 1).Value = slot_plan
- Range("F" & LastRow2 + 1).Value = placa_plan
- Range("G" & LastRow2 + 1).Value = porta_mux_plan
- Range("H" & LastRow2 + 1).Value = porta_pop_plan
- Range("I" & LastRow2 + 1).Value = modem_pop_plan
- Range("J" & LastRow2 + 1).Value = tipo_modem_pop_plan
- Range("K" & LastRow2 + 1).Value = porta_modem_pop_cliente
- Range("L" & LastRow2 + 1).Value = porta_modem_cliente_pop
- Range("M" & LastRow2 + 1).Value = modem_cliente_plan
- Range("O" & LastRow2 + 1).Value = tipo_modem_cliente_plan
- Range("N" & LastRow2 + 1).Value = porta_cli_plan
- Range("P" & LastRow2 + 1).Value = operadora_plan
- Range("Q" & LastRow2 + 1).Value = os_plan
- Range("R" & LastRow2 + 1).Value = status_circuito
- 'RESETA TODAS AS VARIAVEIS UTILIZADAS NO SCRIPT
- circuito_plan = ""
- pop_mux_plan = ""
- nome_mux_plan = ""
- tipo_mux_plan = ""
- ' slot_plan = ""
- ' placa_plan = ""
- porta_mux_plan = ""
- porta_pop_plan = ""
- modem_pop_plan = ""
- tipo_modem_pop_plan = ""
- porta_modem_pop_cliente = ""
- porta_modem_cliente_pop = ""
- modem_cliente_plan = ""
- tipo_modem_cliente_plan = ""
- porta_modem_pop_cliente = ""
- porta_modem_cliente_pop = ""
- porta_cli_plan = ""
- operadora_plan = ""
- os_plan = ""
- status_circuito = ""
- subend = ""
- 'End If ' if vazia = 0 then
- vazia = 0
- Windows(arquivo).Activate
- End If
- Next 'Each celula In Range(ciclo_pop(i))
- ReDim modens(0)
- ReDim tipo_modem(0)
- Next 'For i = 0 To UBound(ciclo_pop)
- End If ' If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- 'AO FIM DE CADA ABA, VERIFICA SE HÁ A NECESSIDADE DE REORGANIZAR AS PORTAS DOS DM705
- If rodada <> 0 Then
- Windows(nova).Activate
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow3 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- dm_on = 0
- 'PEGA CADA CELULA DA COLUNA J QUE COMPREENDE UM RESULTADO DE UMA 'ABA'
- For Each celula_nova In Range("J" & inicio_nova & ":J" & LastRow3)
- 'On Error Resume Next
- '
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow4 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- linha_nova = celula_nova.Row
- 'CASO A PORTA DO MULTIPLEXADOR CONTENHA A LETRA 'P', NAO HÁ NADA A FAZER
- If InStr(1, Range("G" & linha_nova).Value, "P") <> 0 Then
- dm_on = 0
- End If
- 'SE O TIPO DE EQUIPAMENTO FOR DM705, PEGA A PORTA DO MODEM DO POP E O TIPO DELA. O FLAG DM_ON SIGNIFICA QUE FOI ENCONTRADO UM DM705
- 'QUE PRECISA TER OS EQUIPAMENTOS ASSOCIADOS A ELE REARRANJADOS
- If celula_nova.Value = "DM705" Then
- dm_atual = Range("I" & linha_nova).Value
- port_dm_atual = Range("H" & linha_nova).Value
- dm_on = 1
- End If
- 'VERIFICA SE EXISTE ALGUMA VIRGULA NA PORTA DO MUX, EM CASO POSITIVO, SUBSTITUI-AS POR '.'
- If InStr(1, Range("G" & linha_nova).Value, ",") <> 0 Then
- Range("G" & linha_nova).Value = Replace(Range("G" & linha_nova).Value, ",", ".")
- 'CASO NAO HAJA 'P' NA PORTA DO MUX, ASSOCIA-SE A LETRA 'P' A ELA
- If InStr(1, Range("G" & linha_nova).Value, "P") = 0 Then
- Range("G" & linha_nova).Value = "P" & Range("G" & linha_nova).Value
- End If
- End If
- 'CASO EXISTAM 2 LETRAS 'PP' NO MUX, CORRIGE PARA 1 SÓ
- If InStr(1, Range("G" & linha_nova).Value, "PP") <> 0 Then
- Range("G" & linha_nova).Value = Replace(Range("G" & linha_nova).Value, "PP", "P")
- End If
- 'RETIRA-SE A LETRA QUE IDENTIFICA O SLOT DO DM705, CASO NAO EXISTA, ASSUME-SE A LETRA 'A'
- If Not IsEmpty(Range("G" & linha_nova)) And RemoveSpaces(Range("G" & linha_nova).Value) <> "" Then
- tt = Range("G" & linha_nova).Value
- posicaoletra = InStr(1, tt, ".")
- letra = Mid(tt, 1, posicaoletra - 1)
- Else
- letra = "A"
- End If
- 'REORGANIZA OS DADOS DO CIRCUITO PARA REFLETIR A REALIDADE DE UM DM705 - MAIS INFORMACOES COM O RONALDO DA ENGENHARIA
- If (letra = "A" Or letra = "B" Or letra = "C" Or letra = "D" Or letra = "E" Or letra = "F" Or letra = "G" Or letra = "H") And dm_on = 1 Then
- circuito_n = Range("A" & linha_nova).Value
- pop_n = Range("B" & linha_nova).Value
- porta_mux_n = Range("G" & linha_nova).Value
- porta_modem_n = Range("H" & linha_nova).Value
- nome_modem_pop_n = Range("I" & linha_nova).Value
- tipo_modem_pop_n = Range("J" & linha_nova).Value
- porta_modem_pop_cli_n = Range("K" & linha_nova).Value
- porta_modem_cli_pop_n = Range("L" & linha_nova).Value
- modem_cli_n = Range("M" & linha_nova).Value
- porta_modem_cli_n = Range("N" & linha_nova).Value
- tipo_modem_cli_n = Range("O" & linha_nova).Value
- operadora_n = Range("P" & linha_nova).Value
- os_n = Range("Q" & linha_nova).Value
- 'endereco_n = Range("A" & linha_nova).Hyperlinks(1).Address
- status_circuito = Range("R" & linha_nova).Value
- Range("A" & LastRow4 + 1).Value = circuito_n
- Range("B" & LastRow4 + 1).Value = pop_n
- Range("C" & LastRow4 + 1).Value = "DM705"
- Range("D" & LastRow4 + 1).Value = dm_atual
- Range("G" & LastRow4 + 1).Value = porta_mux_n
- Range("H" & LastRow4 + 1).Value = porta_modem_n
- Range("I" & LastRow4 + 1).Value = nome_modem_pop_n
- Range("J" & LastRow4 + 1).Value = tipo_modem_pop_n
- Range("K" & LastRow4 + 1).Value = porta_modem_pop_cli_n
- Range("L" & LastRow4 + 1).Value = porta_modem_cli_pop_n
- Range("M" & LastRow4 + 1).Value = modem_cli_n
- Range("N" & LastRow4 + 1).Value = porta_modem_cli_n
- Range("O" & LastRow4 + 1).Value = tipo_modem_cli_n
- Range("P" & LastRow4 + 1).Value = operadora_n
- Range("Q" & LastRow4 + 1).Value = os_n
- subs_end = "'" & aba & "'!" & RemoveDolars((Range("R" & linha_nova).Value))
- 'ActiveSheet.Hyperlinks.Add Anchor:=Range("A" & LastRow4 + 1), Address:=endereco_n, SubAddress:=subs_end, TextToDisplay:=Range("A" & linha_nova).Value
- Range("R" & LastRow4 + 1).Value = status_circuito
- 'RESETA AS VARIAVEIS
- circuito_n = ""
- pop_n = ""
- porta_mux_n = ""
- porta_modem_n = ""
- nome_modem_pop_n = ""
- tipo_modem_pop_n = ""
- porta_modem_pop_cli_n = ""
- porta_modem_cli_pop_n = ""
- modem_cli_n = ""
- porta_modem_cli_n = ""
- tipo_modem_cli_n = ""
- operadora_n = ""
- os_n = ""
- endereco_n = ""
- status_circuito = ""
- Rows(linha_nova & ":" & linha_nova).Select
- Selection.Interior.ColorIndex = 3
- End If
- Next
- 'APAGA AS LINHAS DESNECESSARIAS QUE FORAM REARRANJADAS PARA O DM705
- For bla = 1 To LastRow4
- linha_apaga = bla
- If Range("A" & bla).Interior.ColorIndex = 3 Then
- Rows(linha_apaga & ":" & linha_apaga).Select
- Selection.Delete Shift:=xlUp
- bla = bla - 1
- If bla < 0 Then
- bla = 1
- End If
- End If
- Next
- 'RETORNA AO ARQUIVO ORIGINAL
- Windows(arquivo).Activate
- End If 'If rodada <> 0 Then
- rodada = 0
- Next ' For Each sheet In ActiveWorkbook.Worksheets
- Windows(arquivo).Activate
- 'FECHA O ARQUIVO DE FACILIDADES
- Windows(arquivo).Close False
- Next ' For sasa = LBound(Filename) To UBound(Filename) ' FOR abre arquivos
- 'ATIVA A PLANILHA NOVA
- Windows(nova).Activate
- 'CRIA UMA NOVA COLUNA PARA INSERÇÃO DAS HIERARQUIAS ENTRE MODENS DO CLIENTE E DO POP(H) E DA HIERARQUIA ENTRE O MODEM DO POP E O MUX (M)
- Range("H:H").Select
- Selection.Insert Shift:=xlToRight
- Range("M:M").Select
- Selection.Insert Shift:=xlToRight
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow5 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- 'SELECIONA O ARQUIVO 'HIERARQUIAS.XLSX'
- Windows("hierarquias.xlsx").Activate
- 'PEGA A QUANTIDADE DE HIERAQUIAS EXISTENTES NO ARQUIVO DE HIERARQUIAS
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow15 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- ' RETORNA A PLANILHA NOVA
- Windows(nova).Activate
- 'VALIDA CADA UMA DAS LINHAS DA PLANILHA NOVA
- For Each celula In Range("A1:A" & LastRow5)
- linha = celula.Row
- 'PEGA OS DADOS DO POP, MUX E EQUIPAMENTO DO CLIENTE
- equip_pop = Range("K" & linha).Value
- equip_mux = Range("C" & linha).Value
- equip_cliente = Range("Q" & linha).Value
- placa = Range("F" & linha).Value
- placa = Mid(placa, 1, InStr(1, placa, ".") - 1)
- Windows("hierarquias.xlsx").Activate
- 'RETORNA A PLANILHA DE HIERARQUIAS PARA COMPARACAO
- hierarquia1 = ""
- hierarquia2 = ""
- For Each celula2 In Range("A1:A" & LastRow15)
- 'COMPARA OS DADOS DE HIERARQUIA ENTRE OS EQUIPAMENTOS DO CLIENTE E POP E SIMULTANEAMENTE COMPARA A HIERARQUIA ENTRE OS EQUIPAMENTOS DO MUX E DO POP
- linha2 = celula2.Row
- compara1 = Range("B" & linha2).Value
- compara2 = Range("D" & linha2).Value
- compara3 = Range("F" & linha2).Value
- compara4 = Range("A" & linha2).Value
- If equip_mux = compara1 And equip_pop = compara2 And equip_cliente = compara3 And placa = compara4 Then
- hierarquia1 = Range("C" & linha2).Value
- hierarquia2 = Range("E" & linha2).Value
- 'QUANTO ENCONTRA TUDO, RETORNA
- GoTo encontrou_hierarq
- End If
- Next
- encontrou_hierarq:
- Windows(nova).Activate
- 'ESCREVE OS VALORES DAS HIERARQUIAS NOS SEUS DEVIDOS LOCAIS
- Range("H" & linha).Value = hierarquia1
- Range("M" & linha).Value = hierarquia2
- ' If RemoveSpaces(hierarquia1) = "" Or RemoveSpaces(hierarquia2) = "" Then
- ' 'retorno_erro = 'erro(plan_erro, nova, "", "", "", "Erro - Tipo de hierarquia inexistente : " & equip_mux & "," & equip_pop & "," & equip_cliente)
- ' Range(linha & ":" & linha).Select
- ' Selection.Clear
- ' End If
- Next
- Windows(nova).Activate
- 'CRIA DUAS COLUNAS NOVAS PARA INSERIR A FRAÇÃO DO TRIBUTARIO QUE É UTILIZADO ENTRE O CLIENTE E O MODEM DO POP E ENTRE O MODEM DO POP E O MUX
- Range("H:H").Select
- Selection.Insert Shift:=xlToRight
- Range("N:N").Select
- Selection.Insert Shift:=xlToRight
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow6 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- For Each celula In Range("A1:A" & LastRow6)
- linha = celula.Row
- ' equipamento_teste = Range("D" & linha).Value
- '
- ' If InStr(1, equipamento_teste, "203") <> 0 Then
- '
- ' huahsuahsas1 = 0
- '
- ' End If
- 'PEGA OS DADOS DAS PORTAS PARA COMPARAR E ENCONTRAR O TRIBUTARIO
- porta_mux = Range("G" & linha).Value
- porta_pop = Range("J" & linha).Value
- porta_pop_cli = Range("M" & linha).Value
- porta_cli_pop = Range("P" & linha).Value
- porta_cli = Range("R" & linha).Value
- 'PEGA OS TIPOS DOS EQUIPAMENTOS (MUX, EQUIP DO LADO DO POP E EQUIP DO LADO DO CLIENTE)
- tipo_mux = Range("C" & linha).Value
- tipo_pop = Range("L" & linha).Value
- tipo_cli = Range("S" & linha).Value
- 'PARA TODO DM705 A FRACAO É IGUAL A PORTA, P1 = FRACAO 1, P2 = FRACAO 2, ETC
- If InStr(1, tipo_mux, "DM705") Then
- fracao_1 = Mid(porta_cli, InStr(1, porta_cli, "P") + 1, Len(porta_cli))
- fracao_2 = Mid(porta_cli, InStr(1, porta_cli, "P") + 1, Len(porta_cli))
- 'PARA TODOS OS OUTROS MUX A FRACAO É 1
- Else
- fracao_1 = "1"
- End If
- 'PARA OS MODENS ASGA 2 E 4E1s, DM4E1S E DM16E1, A REGRA É : A FRACAO É IGUAL A PORTA, P1 = FRACAO 1, P2 = FRACAO 2, ETC
- If tipo_cli = "MOASGA2E1" Or tipo_cli = "MOASGA4E1" Or tipo_cli = "DM4E1S" Or tipo_cli = "DM16E1" Then
- fracao_2 = Mid(porta_cli, InStr(1, porta_cli, "P") + 1, Len(porta_cli))
- End If
- 'PARA OS MODEMS MHMUSIC200 E MHLECAR OU DM706 A FRACAO É 1
- If tipo_cli = "MHMUSIC200" Or tipo_cli = "MHLECAR" Or tipo_cli = "DM706" Then
- fracao_2 = "1"
- End If
- 'PARA OS CABOS_CLI A FRACAO É 1
- If fracao_2 = "" And tipo_cli = "CABO_CLI" Then
- fracao_2 = 1
- End If
- 'PARA OS CONV A FRACAO É 1
- If fracao_2 = "" And tipo_cli = "CONV" Then
- fracao_2 = 1
- End If
- 'SE A FRACAO FOR O1 (RESULTANTE DE PORTAS PO1) A FRACA É 1
- If fracao_1 = "O1" Then
- fracao_1 = "1"
- End If
- 'SE A FRACAO FOR O1 (RESULTANTE DE PORTAS PO1) A FRACA É 1
- If fracao_2 = "O1" Then
- fracao_2 = "1"
- End If
- 'ESCREVE OS VALORES DAS FRACOES GERADAS NAS NOVAS COLUNAS N E H
- Range("H" & linha).Value = fracao_1
- Range("N" & linha).Value = fracao_2
- fracao_1 = ""
- fracao_2 = ""
- 'PARA OS DM705 OS DADOS DE SLOT E PLACA SAO REPLICADOS COM O VALOR DA PORTA E A PORTA DO MUX FICA P1.1
- If tipo_mux = "DM705" Then
- porta_mux = Mid(porta_mux, 1, InStr(1, porta_mux, ".") - 1)
- Range("E" & linha).Value = porta_mux
- Range("F" & linha).Value = porta_mux
- Range("G" & linha).Value = "P1.1"
- End If
- Next
- 'ORGANIZA OS DADOS E GERA NOME PARA CADA COLUNA
- Range("1:1").Select
- Selection.Insert Shift:=xlDown
- Range("A1").Value = "Desig"
- Range("B1").Value = "POP"
- Range("C1").Value = "Tipo EQUIP"
- Range("D1").Value = "Nome Equip"
- Range("E1").Value = "SLOT"
- Range("F1").Value = "PLACA"
- Range("G1").Value = "Porta Placa"
- Range("H1").Value = "Fração"
- Range("I1").Value = "Hierarquia"
- Range("J1").Value = "Porta Modem pop"
- Range("K1").Value = "Modem Pop"
- Range("L1").Value = "Tipo Modem"
- Range("M1").Value = "Porta Otica"
- Range("N1").Value = "Fração"
- Range("O1").Value = "Hierarquia"
- Range("P1").Value = "Porta Otica"
- Range("Q1").Value = "Modem Cliente"
- Range("R1").Value = "Porta Modem Cliente"
- Range("S1").Value = "Tipo Modem Cliente"
- Range("T1").Value = "Operadora"
- Range("U1").Value = "OS"
- Range("V1").Value = "LINK"
- 'APAGA OS REGISTROS VAZIOS
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- lastrow99 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- For i = lastrow99 To 1 Step -1
- If (Range("A" & i).Value = "") Or (IsEmpty(Range("A" & i)) = True) Then
- Range(i & ":" & i).EntireRow.Delete
- End If
- Next i
- 'VOLTA A ATUALIZAR A TELA
- Windows("operadoras.xlsx").Close False
- Windows("hierarquias.xlsx").Close False
- 'Application.ScreenUpdating = True
- ultimamilha = nova
- End Function
- 'FUNCAO PARA VERIFICAR SE A COR DA CELULA NAO É AUTOMATICA (0)
- Public Function checa_cor(linha As Integer, coluna As Integer)
- If Cells(linha, coluna).Interior.ColorIndex <> 1 Or Cells(linha, (coluna - 1)).Interior.ColorIndex <> 1 Or Cells(linha, (coluna + 1)).Interior.ColorIndex <> 1 Then
- checa_cor = 0
- Else
- checa_cor = 1
- End If 'If Cells(linha, coluna).Interior.ColorIndex <> 1 Or Cells(linha, (coluna - 1)).Interior.ColorIndex <> 1 Or Cells(linha, (coluna + 1)).Interior.ColorIndex <> 1 Then
- End Function
- 'FUNCAO PARA PROCURAR A SIGLA DO POP NO BANCO DE DADOS MYSQL
- Public Function acha_sigla_pop(ByVal nome_pop As String) As String
- rs.Open "select sigla_pop from pop where nome_pop = '" & nome_pop & "'"
- acha_sigla_pop = rs!sigla_pop
- rs.Close
- End Function
- 'FUNCAO PARA PROCURAR O TIPO DE EQUIPAMENTO NO BANCO DE DADOS MYSQL
- Public Function acha_tipo_equip(ByVal nome_mux As String) As String
- rs.Open "select t.nome_tipo_equip from mux m join tipo_equip t on m.id_tipo_equip = t.id_tipo_equip where m.nome_mux = '" & nome_mux & "'"
- If rs.RecordCount = 0 Then
- acha_tipo_equip = 99
- Else
- acha_tipo_equip = rs!nome_tipo_equip
- End If
- rs.Close
- End Function
- 'FUNCAO PARA REMOVER O SIMBOLO DE DOLAR ('$') DA CELULA
- Public Function RemoveDolars(strInput As String)
- ' Removes all spaces from a string of text
- Test:
- If InStr(strInput, "$") = 0 Then
- RemoveDolars = strInput
- Else
- strInput = Left(strInput, InStr(strInput, "$") - 1) _
- & Right(strInput, Len(strInput) - InStr(strInput, "$"))
- GoTo Test
- End If
- End Function
- 'FUBNCAO PARA CONTAR A QUANTIDADE DE VEZES QUE UM CARACTER APARECE EM UMA DETERMINADA STRING
- Function countSeparators(ByVal myString As String, ByVal mySeparator As String) As Integer
- countSeparators = UBound(Split(myString, mySeparator))
- End Function
- 'FUNCAO PARA IDENTIFICAR QUAL É A PONTA DO CLIENTE EM UMA DESIGNACAO
- Public Function detecta(ByVal circuito As String, ByVal nova As String, ByVal mux As String) As String
- Windows("operadoras.xlsx").Activate
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow10 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- On Error GoTo achou_operadora
- circuito = LTrim(RTrim(circuito))
- circuito = Replace(circuito, " ", " ")
- separa_1 = Mid(circuito, 1, InStr(1, circuito, " ") - 1)
- separa_2 = Mid(circuito, InStr(1, circuito, " ") + 1, Len(circuito))
- separa_3 = Mid(separa_2, 1, InStr(1, separa_2, " ") - 1)
- lado_a = Mid(separa_1, 4, Len(separa_1))
- lado_b = Mid(separa_3, 4, Len(separa_3))
- lado_a = RTrim(LTrim(lado_a))
- lado_b = RTrim(LTrim(lado_b))
- For Each celula_op In Range("A1:A" & LastRow10)
- If celula_op.Value = lado_a Then
- sigla_operadora = lado_b
- GoTo achou_operadora
- End If
- If celula_op.Value = lado_b Then
- sigla_operadora = lado_a
- GoTo achou_operadora
- End If
- Next
- If InStr(1, lado_a, mux) <> 0 Then
- Range("A" & LastRow10 + 1).Value = lado_a
- sigla_operadora = lado_b
- End If
- If InStr(1, lado_b, mux) <> 0 Then
- Range("A" & LastRow10 + 1).Value = lado_b
- sigla_operadora = lado_a
- End If
- achou_operadora:
- Windows(nova).Activate
- detecta = sigla_operadora
- End Function
- Function ConvertToLetter(ByVal iCol As Integer) As String
- If iCol > 26 Then
- ConvertToLetter = Chr(Int((iCol - 1) / 26) + 64) & Chr(((iCol - 1) Mod 26) + 65)
- Else
- ConvertToLetter = Chr(iCol + 64)
- End If
- End Function
- Public Function primeiramilha(ByRef path As String) As String
- Set rs = New ADODB.Recordset
- ConnectDB
- rs.ActiveConnection = conexao
- rs.LockType = adLockOptimistic
- rs.CursorLocation = adUseClient
- rs.CursorType = adOpenDynamic
- Dim sheet As Worksheet
- Dim celula, celula1 As Range
- Dim LastRow As Long
- Dim Filter As String
- Dim FilterIndex As Integer
- Dim Filename As Variant
- Dim remove As String
- Dim posicao As String
- seq_placa = 1
- id_sheet = 1
- nome_pop = ""
- ' Application.ScreenUpdating = False
- 'With Application.FileDialog(msoFileDialogFolderPicker)
- ' .Show
- ' Path = .SelectedItems(1)
- 'End With
- 'path = "C:\Users\ljunqueira\Documents\Sicop\teste"
- Filename = ListaArquivos(path)
- If Not IsArray(Filename) Then
- MsgBox "Nenhum arquivo selecionado."
- Exit Function
- End If
- principal = ActiveWorkbook.Name
- Workbooks.Add
- ActiveWorkbook.Activate
- nova = ActiveWorkbook.Name
- 'Workbooks.Add
- 'ActiveWorkbook.Activate
- 'erros = ActiveWorkbook.Name
- ' Open Files
- For sasa = LBound(Filename) To UBound(Filename) ' FOR abre arquivos
- If InStr(1, UCase(Filename(sasa)), "XLS") <> 0 Then
- msg = msg & Filename(sasa) & vbCrLf ' This can be removed
- If InStr(1, Filename(sasa), "?") <> 0 Then
- Filename(sasa) = Replace(Filename(sasa), "?", " ")
- End If
- Workbooks.Open Filename(sasa), False
- arquivo = ActiveWorkbook.Name
- Windows(arquivo).Activate
- For Each sheet In ActiveWorkbook.Worksheets
- If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- sheet.Select
- aba = sheet.Name
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Columns.
- LastColumn = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByColumns, _
- SearchDirection:=xlPrevious).Column
- End If
- For Each celula In Range("C3:C" & LastRow)
- linha = celula.Row
- If celula.Interior.ColorIndex = 1 And preta = 0 Then
- For Each celula2 In Range("E" & linha & ":" & ConvertToLetter(LastColumn) & linha)
- If UCase(RemoveSpaces(celula2.Value)) = "FILA" Then
- fila_col = ConvertToLetter(celula2.Column)
- GoTo Achou
- End If 'If UCase(RemoveSpaces(celula2)).Value = "FILA" Then
- If UCase(RemoveSpaces(celula2.Value)) = "DID" Then
- did_col = ConvertToLetter(celula2.Column)
- GoTo Achou
- End If 'If UCase(RemoveSpaces(celula2)).Value = "FILA" Then
- If UCase(RemoveSpaces(celula2.Value)) = "RÉGUA" Then
- regua_col = ConvertToLetter(celula2.Column)
- GoTo Achou
- End If 'If UCase(RemoveSpaces(celula2)).Value = "FILA" Then
- If UCase(RemoveSpaces(celula2.Value)) = "POSIÇÃO" Then
- posicao_col = ConvertToLetter(celula2.Column)
- End If 'If UCase(RemoveSpaces(celula2)).Value = "FILA" Then
- Achou:
- If fila_col <> "" And did_col <> "" And regua_col <> "" And posicao_col <> "" Then
- Exit For
- End If
- porta_col = "H"
- Next 'For Each celula In Range("A" & linha & ":" & LastColumn & linha)
- preta = 1
- nome_mux = Range("C" & linha).Value
- tipo_mux = Range("G" & linha).Value
- If tipo_mux = "" Then
- tipo_mux = Range("F" & linha).Value
- End If
- If tipo_mux = "" Then
- tipo_mux = Range("H" & linha).Value
- End If
- endereco = Range("E" & linha).Value
- If nome_pop = "" Then
- nome_pop = Range("E3").Value
- sigla_pop = Range("C3").Value
- End If
- Else
- If Not IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) <> "" Then
- placa = Range("F" & linha).Value
- placa = UCase(RemoveSpaces(placa))
- ' sigla_pop = acha_sigla(nome_mux)
- placa = placa & "." & sigla_pop & "." & seq_placa
- seq_placa = seq_placa + 1
- End If ' If Not IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) <> "" Then
- If Not IsEmpty(Range("G" & linha).Value) And RemoveSpaces(Range("G" & linha).Value) <> "" Then
- slot = Range("G" & linha).Value
- End If ' If Not IsEmpty(Range("G" & linha).Value) And RemoveSpaces(Range("G" & linha).Value) <> "" Then
- If Not IsEmpty(Range("C" & linha).Value) And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("H" & linha).Value) And RemoveSpaces(Range("H" & linha).Value) <> "" Then
- If UCase(RemoveSpaces(Range("H2").Value)) = "FILA" Then
- porta_col = "G"
- fila_col = "H"
- did_col = "I"
- regua_col = "J"
- posicao_col = "K"
- End If
- If UCase(RemoveSpaces(Range("I2").Value)) = "FILA" Then
- porta_col = "H"
- fila_col = "I"
- did_col = "J"
- regua_col = "K"
- posicao_col = "L"
- End If
- If fila_col = "" Then
- ''retorno_erro = 'erro(erros, arquivo, "", "", "", "Erro - Arquivo não formatado : " & arquivo)
- GoTo proximo_col
- End If
- circuito = Range("C" & linha).Value
- porta = Range(porta_col & linha).Value
- If Not IsEmpty(Range(fila_col & linha)) And RemoveSpaces(Range(fila_col & linha).Value) <> "" Then
- fila = "'" & Range(fila_col & linha).Value
- Else 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
- fila = "-"
- End If 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
- If Not IsEmpty(Range(did_col & linha)) And RemoveSpaces(Range(did_col & linha).Value) <> "" Then
- did = "'" & Range(did_col & linha).Value
- Else 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
- did = "-"
- End If 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
- If Not IsEmpty(Range(regua_col & linha)) And RemoveSpaces(Range(regua_col & linha).Value) <> "" Then
- regua = "'" & Range(regua_col & linha).Value
- Else 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
- regua = "-"
- End If 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
- If Not IsEmpty(Range(posicao_col & linha)) And RemoveSpaces(Range(posicao_col & linha).Value) <> "" Then
- posicao = "'" & Range(posicao_col & linha).Value
- Else 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
- posicao = "-"
- End If 'if not isempty(Range(fila_col & linha)) and removespaces(fila) <> "" then
- Windows(nova).Activate
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow2 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- Range("A" & LastRow2 + 1).Value = id_sheet
- id_sheet = id_sheet + 1
- Range("B" & LastRow2 + 1).Value = sigla_pop
- Range("C" & LastRow2 + 1).Value = endereco
- Range("D" & LastRow2 + 1).Value = nome_mux
- Range("E" & LastRow2 + 1).Value = tipo_mux
- Range("F" & LastRow2 + 1).Value = slot
- Range("G" & LastRow2 + 1).Value = placa
- Range("H" & LastRow2 + 1).Value = porta
- Range("I" & LastRow2 + 1).Value = fila
- Range("J" & LastRow2 + 1).Value = did
- Range("K" & LastRow2 + 1).Value = regua
- Range("L" & LastRow2 + 1).Value = posicao
- Range("M" & LastRow2 + 1).Value = circuito
- Range("N" & LastRow2 + 1).Value = arquivo
- Windows(arquivo).Activate
- porta = ""
- fila = ""
- did = ""
- regua = ""
- posicao = ""
- circuito = ""
- End If ' If Not IsEmpty(Range("C" & linha).Value) And RemoveSpaces(Range("C" & linha).Value) <> "" Then
- End If
- proximo_col:
- Next ' For Each celula In Range("A3:A" & LastRow)
- End If ' If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- preta = 0
- fila_col = ""
- did_col = ""
- regua_col = ""
- posicao_col = ""
- nome_pop = ""
- Next ' For Each sheet In ActiveWorkbook.Worksheets
- Windows(arquivo).Close False
- End If
- Next ' For sasa = LBound(Filename) To UBound(Filename) ' FOR abre arquivos
- Application.ScreenUpdating = True
- primeiramilha = nova
- End Function
- Public Function acha_sigla(ByVal nome_mux As String) As String
- rs.Open "select p.sigla_pop from mux m join pop p on m.id_pop = p.id_pop where m.nome_mux = '" & nome_mux & "'"
- acha_sigla = rs!sigla_pop
- rs.Close
- End Function
- Public Function acha_nome_pop(ByVal nome_mux As String) As String
- rs.Open "select p.nome_pop from mux m join pop p on m.id_pop = p.id_pop where m.nome_mux = '" & nome_mux & "'"
- acha_nome_pop = rs!nome_pop
- rs.Close
- End Function
- Public Function ListaArquivos(ByVal Caminho As String) As String()
- Dim FSO As New FileSystemObject
- Dim result() As String
- Dim result2 As Variant
- Dim Pasta As Folder
- Dim SubPasta As Folder
- Dim arquivo As File
- Dim Indice As Long
- Dim s1 As String
- ReDim result(0) As String
- If FSO.FolderExists(Caminho) Then
- Set Pasta = FSO.GetFolder(Caminho)
- For Each arquivo In Pasta.Files
- If arquivo.Type Like "*Planilha*" Then
- Indice = IIf(result(0) = "", 0, Indice + 1)
- ReDim Preserve result(Indice) As String
- If InStr(1, arquivo.path, " ") <> 0 Then
- caminho_arquivo = Replace(arquivo.path, " ", "?")
- Else
- caminho_arquivo = arquivo.path
- End If
- result(Indice) = caminho_arquivo
- End If
- Next
- For Each SubPasta In Pasta.SubFolders
- result2 = ListaArquivos(SubPasta.path)
- s1 = Join(result, " ") + " "
- s1 = s1 + Join(result2, " ")
- result = Split(s1, " ")
- Next
- End If
- ListaArquivos = result
- ErrHandler:
- Set FSO = Nothing
- Set Pasta = Nothing
- Set arquivo = Nothing
- End Function
- Public Function canalizados_pla(Filename As Variant) As String
- ' Declaracao de variaveis
- Dim sheet As Worksheet
- Dim celula, celula1 As Range
- Dim LastRow As Long
- Dim Filter As String
- Dim FilterIndex As Integer
- 'Dim filename As Variant
- Dim remove As String
- Dim path As String
- Dim filename_path As Variant
- Dim canalizados() As canalizados
- Dim array_temp() As array_canal
- ReDim Preserve canalizados(0)
- ReDim Preserve array_temp(0)
- Dim ultima_milha() As ultima_milha
- ReDim Preserve ultima_milha(0)
- Dim mux As String
- 'Não atualizar a tela durante o script.
- 'Application.ScreenUpdating = False
- ' File filters - Filtro dos tipos de arquivos que aparecem na caixa de dialogo de escolha do arquivo.
- 'Filter = "Excel Files (*.xls),*.xls," & _
- '"Text Files (*.txt),*.txt," & _
- '"All Files (*.*),*.*"
- ' Default filter to *.*
- 'FilterIndex = 3
- ' Set Dialog Caption
- 'TITULO DA CAIXA
- 'Title = "Escolha o arquivo de circuitos "
- ' Select Start Drive & Path - Caminho da caixa de dialogo.
- 'ChDrive ("C")
- 'ChDir ("C:\")
- 'ABRE CADA ARQUIVO SELECIONADO DA CAIXA DE DIALOGO
- 'With Application
- 'Set File Name Array to selected Files (allow multiple)
- 'Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
- 'Reset Start Drive/Path
- 'ChDrive (Left(.DefaultFilePath, 1))
- 'ChDir (.DefaultFilePath)
- 'End With
- 'Exit on Cancel
- ' File filters
- 'principal = ActiveWorkbook.Name
- 'Workbooks.Add
- 'ActiveWorkbook.Activate
- 'plan_erro = ActiveWorkbook.Name
- ' Open Files
- tamanho_filename = UBound(Filename)
- If tamanho_filename = 0 Then
- inicio = 0
- fim = 0
- Else
- inicio = LBound(Filename)
- fim = (UBound(Filename)) - 1
- End If
- For sasa = inicio To fim ' FOR abre arquivos
- msg = msg & Filename(sasa) & vbCrLf ' This can be removed
- 'Workbooks.Open Filename(sasa), False
- formata = sicop(Filename(sasa))
- arquivo = ActiveWorkbook.Name
- If arquivo Like "*Interior*" Then
- caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Interior"
- Else
- caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Região_Metropolitana"
- End If
- end2 = (caminhoarquivo & "\" & arquivo)
- Windows(arquivo).Activate
- For Each sheet In ActiveWorkbook.Worksheets
- If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- sheet.Select
- aba = sheet.Name
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- For Each celula In Range("C3:C" & LastRow)
- linha = celula.Row
- ' If Trim(UCase(Range("C" & linha).Value)) = "BHEFDT2 BHETFA4 1984K-01" Then
- '
- ' bla111 = 0
- '
- ' End If
- If Range("C" & linha).Interior.ColorIndex = 1 Then
- mux_milha = Range("C" & linha).Value
- If Not IsEmpty(Range("K" & linha)) And RemoveSpaces(Range("K" & linha).Value) <> "" Then
- tipo_mux = Range("K" & linha).Value
- ElseIf Not IsEmpty(Range("L" & linha)) And RemoveSpaces(Range("L" & linha).Value) <> "" Then
- tipo_mux = Range("L" & linha).Value
- Else
- tipo_mux = Range("M" & linha).Value
- End If
- End If
- If Not IsEmpty(Range("L" & linha)) And RemoveSpaces(Range("L" & linha).Value) <> "" Then
- slot_mux = UCase(Range("L" & linha).Value)
- If InStr(1, slot_mux, "S") <> 0 Then
- slot_mux = Replace(slot_mux, "S", "")
- End If 'If InStr(1, slot_mux, "S") <> 0 Then
- End If 'If Not IsEmpty(Range("L" & linha)) And RemoveSpaces(Range("L" & linha).Value) <> "" Then
- If Range("C" & linha).Interior.ColorIndex <> 1 And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("C" & linha)) Then
- If Not IsEmpty(Range("M" & linha)) And RemoveSpaces(Range("M" & linha).Value) <> "" Then
- porta_mux = UCase(Range("M" & linha).Value)
- If InStr(1, porta_mux, "P") <> 0 Then
- porta_mux = Replace(porta_mux, "P", "")
- End If
- If InStr(1, porta_mux, ".") <> 0 Then
- porta_mux = Replace(porta_mux, ".", ",")
- End If
- search_letra = letra_func(porta_mux)
- If search_letra <> 0 Then
- porta_mux = search_letra
- End If
- End If
- velocidade = Range("D" & linha).Value
- canal = checa_canalizado(velocidade)
- If canal = 1 Then
- If InStr(1, Range("C" & linha).Value, " ") <> 0 Then
- Range("C" & linha).Value = Replace(Range("C" & linha).Value, " ", " ")
- ElseIf InStr(1, Range("C" & linha).Value, " ") <> 0 Then
- Range("C" & linha).Value = Replace(Range("C" & linha).Value, " ", " ")
- End If
- ultima_milha(UBound(ultima_milha)).circuito = UCase(Trim(Range("C" & linha).Value))
- ultima_milha(UBound(ultima_milha)).mux = mux_milha
- ultima_milha(UBound(ultima_milha)).arquivo = arquivo
- ultima_milha(UBound(ultima_milha)).aba = aba
- ultima_milha(UBound(ultima_milha)).subend = ("'" & aba & "'!" & RemoveDolars(Range("C" & linha).Address))
- ultima_milha(UBound(ultima_milha)).end2 = end2
- ultima_milha(UBound(ultima_milha)).porta_mux = porta_mux
- ultima_milha(UBound(ultima_milha)).slot_mux = slot_mux
- ultima_milha(UBound(ultima_milha)).tipo_mux = tipo_mux
- ReDim Preserve ultima_milha(UBound(ultima_milha) + 1)
- End If ' If canal = 1 Then
- End If 'If Range("C" & linha).Interior.ColorIndex <> 1 And RemoveSpaces(Range("C" & linha).Value) <> "" And Not IsEmpty(Range("C" & linha)) Then
- Next
- End If ' If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- Next 'For Each sheet In ActiveWorkbook.Worksheets
- Windows(arquivo).Close False
- Next
- profile_folder = GetSpecialFolderPaths()
- array_canalizados = profile_folder & "\SICOP\Facilidades\Canalizados\"
- 'SALVA O NOME DA PLANILHA (ARQUIVO) ABERTA PARA TRANSIÇÃO ENTRE PLANILHA
- principal = ActiveWorkbook.Name
- 'ABRE UMA NOVA PLANILHA
- 'Workbooks.Add
- 'ActiveWorkbook.Activate
- 'SALVA O NOME DA NOVA PLANILHA
- 'erros = ActiveWorkbook.Name
- 'Windows(erros).Activate
- 'ABRE UMA NOVA PLANILHA
- Workbooks.Add
- ActiveWorkbook.Activate
- 'SALVA O NOME DA NOVA PLANILHA
- nova = ActiveWorkbook.Name
- 'Windows(nova).Activate
- 'For ca = LBound(array_canalizados) To UBound(array_canalizados) ' FOR abre pastas
- 'Pega o caminho de todos os arquivos dentro de uma pasta
- path = array_canalizados
- 'path = "C:\Users\ljunqueira\Documents\Sicop\teste"
- filename_path = ListaArquivos(path)
- If Not IsArray(filename_path) Then
- MsgBox "Nenhum arquivo selecionado."
- Exit Function
- End If
- ' Open Files - ABRE CADA UM DOS ARQUIVOS SELECIONADOS NA CAIXA DE DIALOGO EM UM LOOP
- For sasa = LBound(filename_path) To UBound(filename_path) ' FOR abre arquivos
- If InStr(1, UCase(filename_path(sasa)), "XLS") <> 0 Then
- msg = msg & filename_path(sasa) & vbCrLf ' This can be removed
- If InStr(1, filename_path(sasa), "?") <> 0 Then
- filename_path(sasa) = Replace(filename_path(sasa), "?", " ")
- End If
- Workbooks.Open filename_path(sasa), False
- 'SALVA O NOME DA PLANILHA ABERTA QUE FOI SELECIONADA NA CAIXA DE DIALOGO
- arquivo = ActiveWorkbook.Name
- 'ATIVA A PLANILHA INICIAL ONDE O SCRIPT ESTA RODANDO
- Windows(arquivo).Activate
- 'DEFINE O CAMINHO DA PLANILHA ATUAL
- caminhoarquivo = ActiveWorkbook.path
- 'CRIA O CAMINHHO + NOME DA PLANILHA ATUAL
- end2 = (caminhoarquivo & "\" & arquivo)
- 'EXECUTA UM LOOP EM CADA UMA DAS ABAS DA PLANILHA ABERTA
- For Each sheet In ActiveWorkbook.Worksheets
- canalizado = ""
- circuito = ""
- If UCase(sheet.Name) <> "ÍNDICE" Then
- sheet.Select
- aba = sheet.Name
- If ((Trim(UCase(Range("A1").Value)) Like "*FACILIDADE*") And (Trim(UCase(Range("D1").Value)) = "CIRCUITOS")) Then
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- For Each celula In Range("A1:A" & LastRow)
- linha = celula.Row
- Range("D" & linha).Select
- If canalizado <> "" And Not IsEmpty(Range("D" & linha).Value) And Range("D" & linha).Interior.ColorIndex <> 1 And linha <> 1 And circuito = "" And InStr(UCase(Range("D" & linha).Value), "EXCLUSIVO") = 0 Then
- circuito = Trim(Range("D" & linha).Value)
- If InStr(1, circuito, " ") <> 0 Then
- circuito = Replace(circuito, " ", " ")
- ElseIf InStr(1, circuito, " ") <> 0 Then
- circuito = Replace(circuito, " ", " ")
- End If
- ts_ini = Range("B" & linha).Value
- If Len(ts_ini) = 1 Then
- ts_ini = "0" & ts_ini
- End If
- End If
- If linha <> 1 Then
- canalizado = Trim(Range("A" & linha).Value)
- If InStr(1, canalizado, " ") <> 0 Then
- canalizado = Replace(canalizado, " ", " ")
- ElseIf InStr(1, canalizado, " ") <> 0 Then
- canalizado = Replace(canalizado, " ", " ")
- End If
- If InStr(1, canalizado, "/") <> 0 Then
- canalizado = Replace(canalizado, "/", "")
- End If
- circuito_atual = Range("D" & linha).Value
- x = Range("C" & linha).Value
- ts = Range("B" & linha).Value
- cor_linha = Range("D" & linha).Interior.ColorIndex
- If circuito_atual <> circuito And ts <> ts_ini And cor_linha <> 1 And Not IsEmpty(circuito_atual) Then
- ts_fim = Range("B" & (linha - 1)).Value
- If Len(ts_fim) = 1 Then
- ts_fim = "0" & ts_fim
- End If
- canalizados(UBound(canalizados)).facilidade = canalizado
- canalizados(UBound(canalizados)).circuito = RemoveSpaces(UCase(circuito))
- canalizados(UBound(canalizados)).vc = "'" & ts_ini & "-" & ts_fim
- canalizados(UBound(canalizados)).aba = aba
- canalizados(UBound(canalizados)).arquivo = arquivo
- 'canalizados(UBound(canalizados)).subend = ("'" & aba & "'!" & Removedolars(Range("D" & linha).Address))
- ReDim Preserve canalizados(UBound(canalizados) + 1)
- ts_ini = Range("B" & linha).Value
- If Len(ts_ini) = 1 Then
- ts_ini = "0" & ts
- End If
- circuito = Range("D" & linha).Value
- End If
- If (RemoveSpaces(UCase(Range("C" & linha - 1).Value)) = "X" And IsEmpty(x)) Or (UCase(RemoveSpaces(x)) Like "*EXCLUSIVO*") Then
- ts_fim = Range("B" & (linha - 1)).Value
- If Len(ts_fim) = 1 Then
- ts_fim = "0" & ts
- End If
- If canalizado = "" Then
- canalizado = Range("A" & (linha - 1)).Value
- If InStr(1, canalizado, "/") <> 0 Then
- canalizado = Replace(canalizado, "/", "")
- End If
- If InStr(1, canalizado, " ") <> 0 Then
- canalizado = Replace(canalizado, " ", " ")
- ElseIf InStr(1, canalizado, " ") <> 0 Then
- canalizado = Replace(canalizado, " ", " ")
- End If
- End If
- canalizados(UBound(canalizados)).facilidade = Trim(canalizado)
- canalizados(UBound(canalizados)).circuito = RemoveSpaces(UCase(circuito))
- canalizados(UBound(canalizados)).vc = "'" & ts_ini & "-" & ts_fim
- canalizados(UBound(canalizados)).aba = aba
- canalizados(UBound(canalizados)).arquivo = arquivo
- 'canalizados(UBound(canalizados)).subend = ("'" & aba & "'!" & Removedolars(Range("D" & linha).Address))
- ReDim Preserve canalizados(UBound(canalizados) + 1)
- ts_ini = ""
- circuito = ""
- End If
- End If ' If linha <> 1 Then
- Next
- If linha = LastRow And RemoveSpaces(UCase(Range("C" & linha).Value)) = "X" Then
- ts_fim = Range("B" & (linha)).Value
- If Len(ts_fim) = 1 Then
- ts_fim = "0" & ts
- End If
- canalizados(UBound(canalizados)).facilidade = canalizado
- canalizados(UBound(canalizados)).circuito = UCase(RemoveSpaces(circuito))
- canalizados(UBound(canalizados)).vc = "'" & ts_ini & "-" & ts_fim
- canalizados(UBound(canalizados)).aba = aba
- canalizados(UBound(canalizados)).arquivo = arquivo
- 'canalizados(UBound(canalizados)).subend = ("'" & aba & "'!" & Removedolars(Range("D" & linha).Address))
- ReDim Preserve canalizados(UBound(canalizados) + 1)
- ts_ini = ""
- circuito = ""
- End If
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("A1").Address))
- 'retorno_erro = 'erro(erros, arquivo, end2, subend_erro, Range("A1").Value, "Erro - Arquivo não formatado : " & end2 & "\" & arquivo)
- End If ' If ((Trim(UCase(Range("A1").Value)) <> "FACILIDADES") Or (Trim(UCase(Range("D1").Value)) <> "CIRCUITOS")) Then
- End If 'If UCase(sheet.Name) <> "ÍNDICE" Then
- Next 'For Each sheet In ActiveWorkbook.Worksheets
- 'FECHA O ARQUIVO ABERTO SELECIONADO NA CAIXA DE DIALOGO PARA CONTINUAR O LOOP
- Windows(arquivo).Close False
- End If ' If InStr(1, Filename(sasa), "xls") <> 0 Then
- Next ' cada arquivo - FOR
- linhas = 1
- For y = LBound(ultima_milha) To (UBound(ultima_milha) - 1)
- circuito_original = ultima_milha(y).circuito
- valor = RemoveSpaces(UCase(circuito_original))
- t = 0
- Erase array_temp
- ReDim Preserve array_temp(0)
- For i = LBound(canalizados) To UBound(canalizados)
- If valor = canalizados(i).circuito Then
- array_temp(t).n64 = canalizados(i).circuito
- array_temp(t).ts = canalizados(i).vc
- array_temp(t).facilidade = canalizados(i).facilidade
- ReDim Preserve array_temp(UBound(array_temp) + 1)
- t = t + 1
- End If
- Next
- Windows(nova).Activate
- Range("A" & linhas).Value = ultima_milha(y).mux
- 'Range("B" & linhas).Value = circuito_original
- Range("B" & linhas).Select
- ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=ultima_milha(y).end2, SubAddress:=ultima_milha(y).subend, TextToDisplay:=ultima_milha(y).circuito
- ultima_coluna = 3
- For i = LBound(array_temp) To (UBound(array_temp) - 1)
- Range(ConvertToLetter(ultima_coluna) & linhas).Value = array_temp(i).facilidade
- Range(ConvertToLetter(ultima_coluna + 1) & linhas).Value = array_temp(i).ts
- ultima_coluna = ultima_coluna + 2
- Next
- linhas = linhas + 1
- Next ' For y = LBound(ultima_minha) To (UBound(ultima_milha) - 1)
- Dim swap() As String
- ReDim Preserve swap(0)
- swap_ok = 0
- Windows(nova).Activate
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- For Each celula In Range("A1:A" & LastRow)
- linha = celula.Row
- mux = Range("A" & linha).Value
- canalizado = Range("B" & linha).Value
- ultima_coluna = LastColumnInOneRow(linha)
- For i = 2 To ultima_coluna
- If i Mod 2 = 1 Then
- facilidade = Range(ConvertToLetter(i) & linha).Value
- comeco = Mid(facilidade, 1, InStr(1, facilidade, " ") - 1)
- intermed = Mid(facilidade, InStr(1, facilidade, " ") + 1, Len(facilidade))
- fim = Mid(intermed, 1, InStr(1, intermed, " ") - 1)
- equip1 = Mid(comeco, 4, Len(comeco))
- equip2 = Mid(fim, 4, Len(fim))
- If InStr(1, equip1, mux) <> 0 Then
- If coluna_inicio = "" Then
- coluna_inicio = ConvertToLetter(i)
- prox_equip = equip2
- Else
- 'retorno_erro = 'erro(erros, nova, "", "", "", "Erro - O canalizado Nx64 tem mais de uma origem : " & canalizado)
- End If 'If coluna_inicio = "" Then
- ElseIf InStr(1, equip2, mux) <> 0 Then
- If coluna_inicio = "" Then
- coluna_inicio = ConvertToLetter(i)
- prox_equip = equip1
- Else
- 'retorno_erro = 'erro(erros, nova, "", "", "", "Erro - O canalizado Nx64 tem mais de uma origem : " & canalizado)
- End If 'If coluna_inicio = "" Then
- End If 'If InStr(1, equip1, mux) <> 0 Then
- End If ' If i Mod 2 = 1 Then
- Next 'For i = 2 To ultima_coluna
- If coluna_inicio <> "" Then
- swap(UBound(swap)) = coluna_inicio
- ReDim Preserve swap(UBound(swap) + 1)
- iteracoes = (ultima_coluna / 2) - 1
- For i = 1 To iteracoes
- procura = procura_next(prox_equip, coluna_inicio, linha, ultima_coluna)
- If procura <> 0 Then
- nova_coluna = Mid(procura, 1, InStr(1, procura, ".") - 1)
- novo_equip = Mid(procura, InStr(1, procura, ".") + 1, Len(procura))
- swap(UBound(swap)) = nova_coluna
- ReDim Preserve swap(UBound(swap) + 1)
- prox_equip = novo_equip
- coluna_inicio = nova_coluna
- Else ' If procura <> 0 Then
- tam_array = UBound(swap)
- facilidade = Range("B" & linha).Value
- num_espaco = countSeparators(facilidade, " ")
- If num_espaco = 2 Then
- If iteracoes = tam_array Then
- comeco = Mid(facilidade, 1, InStr(1, facilidade, " ") - 1)
- intermed = Mid(facilidade, InStr(1, facilidade, " ") + 1, Len(facilidade))
- fim = Mid(intermed, 1, InStr(1, intermed, " ") - 1)
- equip1 = Mid(comeco, 4, Len(comeco))
- equip2 = Mid(fim, 4, Len(fim))
- If InStr(1, equip1, prox_equip) <> 0 Then
- swap_ok = 1
- ElseIf InStr(1, equip2, prox_equip) <> 0 Then ' If InStr(1, equip1, prox_equip) <> 0 Then
- swap_ok = 1
- End If ' If InStr(1, equip1, prox_equip) <> 0 Then
- End If ' If iteracoes = tam_array Then
- Else ' If num_espaco = 2 Then
- 'retorno_erro = 'erro(erros, nova, "", "", "", "Erro - Designacao invalida para o circuito : " & facilidade)
- End If
- End If ' If procura <> 0 Then
- Next 'For i = 1 To iteracoes
- End If
- If swap_ok = 0 Then
- 'retorno_erro = 'erro(erros, nova, "", "", "", "Erro - Não foram encontrados todos os 2M para o canalizado : " & canalizado)
- Else
- ordenado_function = ordena_swap(swap(), linha)
- End If
- coluna_inicio = ""
- swap_ok = 0
- ReDim swap(0)
- Next 'For Each celula In Range("A1:A" & LastRow)
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- For i = 1 To LastRow
- circuito = Range("B" & i).Value
- For j = 0 To UBound(ultima_milha)
- circ_UM = ultima_milha(j).circuito
- If UCase(RemoveSpaces(circuito)) = UCase(RemoveSpaces(circ_UM)) Then
- 'Range("W" & i) = ultima_milha(j).circuito
- Range("W" & i) = ultima_milha(j).mux
- Range("X" & i) = ultima_milha(j).tipo_mux
- Range("Y" & i) = ultima_milha(j).slot_mux
- If InStr(1, ultima_milha(j).porta_mux, ",") <> 0 Then
- fracao_porta = Mid(ultima_milha(j).porta_mux, InStr(1, ultima_milha(j).porta_mux, ",") + 1, Len(ultima_milha(j).porta_mux))
- ultima_milha(j).porta_mux = Mid(ultima_milha(j).porta_mux, 1, InStr(1, ultima_milha(j).porta_mux, ",") - 1)
- If InStr(1, fracao_porta, ",") <> 0 Then
- fracao_porta = Mid(fracao_porta, InStr(1, fracao_porta, ",") + 1, Len(fracao_porta))
- End If
- Else
- fracao_porta = 1
- End If
- Range("Z" & i) = ultima_milha(j).porta_mux
- Range("AA" & i) = fracao_porta
- 'Range("AA" & linha).Select
- 'ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=ultima_milha(j).end2, SubAddress:=subend, TextToDisplay:=circuito_plan
- Exit For
- End If 'If UCase(RemoveSpaces(circuito)) = UCase(RemoveSpaces(circ_UM)) Then
- Next 'For j = 0 To UBound(ultima_milha)
- Next 'For i = 1 To LastRow
- Range("A:A").Select
- Selection.Delete Shift:=xlToLeft
- Rows("1:1").Select
- Selection.Insert Shift:=xlDown
- Range("A1").Value = "N64"
- Range("B1").Value = "Canalizado"
- Range("C1").Value = "Timeslot"
- Range("D1").Value = "Canalizado"
- Range("E1").Value = "Timeslot"
- Range("F1").Value = "Canalizado"
- Range("G1").Value = "Timeslot"
- Range("H1").Value = "Canalizado"
- Range("I1").Value = "Timeslot"
- Range("J1").Value = "Canalizado"
- Range("K1").Value = "Timeslot"
- Range("L1").Value = "Canalizado"
- Range("M1").Value = "Timeslot"
- Range("N1").Value = "Canalizado"
- Range("O1").Value = "Timeslot"
- Range("P1").Value = "Canalizado"
- Range("Q1").Value = "Timeslot"
- Range("R1").Value = "Canalizado"
- Range("S1").Value = "Timeslot"
- Range("T1").Value = "Canalizado"
- Range("U1").Value = "Timeslot"
- Range("V1").Value = "MUX"
- Range("W1").Value = "TIPO_EQUIP"
- Range("X1").Value = "SLOT"
- Range("Y1").Value = "PORTA"
- Range("Z1").Value = "FRACAO"
- 'Next 'For ca = LBound(array_canalizados) To UBound(array_canalizados) ' FOR abre pastas
- 'Application.ScreenUpdating = True
- canalizados_pla = nova
- End Function
- Public Function sicop(ByVal arquivo_input As String) As Integer
- 'Public Sub sicop()
- Dim ciclo() As String
- Dim ciclo_pop() As String
- Dim ciclo_placa() As String
- Dim mux() As String
- 'CRIA A CONEXAO COM O BANCO
- Set rs = New ADODB.Recordset
- ConnectDB
- rs.ActiveConnection = conexao
- rs.LockType = adLockOptimistic
- rs.CursorLocation = adUseClient
- rs.CursorType = adOpenDynamic
- 'DECLARACAO DE VARIAVEIS
- Dim sheet As Worksheet
- Dim celula, celula1 As Range
- Dim LastRow As Long
- Dim Filter As String
- Dim FilterIndex As Integer
- Dim Filename As Variant
- Dim remove As String
- Dim i As Integer
- ReDim Preserve ciclo(0)
- ReDim Preserve ciclo_pop(0)
- ReDim Preserve mux(0)
- ReDim Preserve ciclo_placa(0)
- Dim modens() As modens
- Dim placas() As placas
- Dim portas() As portas
- Dim tipo_modem() As tipo_modem
- ReDim Preserve modens(0)
- ReDim Preserve tipo_modem(0)
- ReDim Preserve placas(0)
- ReDim Preserve portas(0)
- Dim m As Integer
- Dim n As Integer
- rodada = 0
- 'NAO ATUALIZA A TELA
- ' Application.ScreenUpdating = False
- '
- '
- ' ' File filters
- ' Filter = "Excel Files (*.xls),*.xls," & _
- ' "Text Files (*.txt),*.txt," & _
- ' "All Files (*.*),*.*"
- ' ' Default filter to *.*
- ' FilterIndex = 3
- ' ' Set Dialog Caption
- ' Title = "Escolha o arquivo de circuitos "
- ' ' Select Start Drive & Path
- ' ChDrive ("C")
- ' ChDir ("C:\Users\acunha\Desktop\Trabalho\Engenharia\Facilidades\2012-11-06")
- ' With Application
- ' ' Set File Name Array to selected Files (allow multiple)
- ' Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
- ' ' Reset Start Drive/Path
- ' ChDrive (Left(.DefaultFilePath, 1))
- ' ChDir (.DefaultFilePath)
- ' End With
- ' ' Exit on Cancel
- '
- ' If Not IsArray(Filename) Then
- ' MsgBox "Nenhum arquivo selecionado."
- ' Exit Function
- ' End If
- 'CRIA 1 NOVA PLANILHA
- ' principal = ActiveWorkbook.Name
- ' Workbooks.Add
- ' ActiveWorkbook.Activate
- ' nova = ActiveWorkbook.Name
- ' Windows(nova).Activate
- ' Cells.Select
- ' Selection.NumberFormat = "@"
- ' Range("A1").Select
- ' Workbooks.Add
- ' ActiveWorkbook.Activate
- ' plan_erro = ActiveWorkbook.Name
- ' Windows(principal).Activate
- 'LOOP DOS ARQUIVOS SELECIONADOS - CONTROLE DE FACILIDADES
- ' Open Files
- 'For sasa = LBound(filename) To UBound(filename) ' FOR abre arquivos
- ' msg = msg & Filename(sasa) & vbCrLf ' This can be removed
- Workbooks.Open arquivo_input, False
- arquivo = ActiveWorkbook.Name
- Windows(arquivo).Activate
- 'caminhoarquivo = ActiveWorkbook.Path
- 'DEFINE O CAMINHO DO ARQUIVO PARA CRIAR HYPERLINKS
- If arquivo Like "*Interior*" Then
- caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Interior"
- Else
- caminhoarquivo = "\\db_server.infoviasnet.com.br\Facilidades\Controle_de_Facilidades\Região_Metropolitana"
- End If
- end2 = (caminhoarquivo & "\" & arquivo)
- 'TRATA CADA UMA DAS ABAS DAS PLANILHAS
- For Each sheet In ActiveWorkbook.Worksheets
- rpt = 0
- 'IGNORA TODAS AS PLANILHAS QUE TEM RPT NO NOME - PLANILHAS DE RÁDIO
- ' If sheet.Name Like "*RPT*" Then
- '
- ' rpt = 1
- '
- ' End If
- 'IGNORA AS PLANILHAS QUE NÃO SÃO ULTIMA MILHA
- If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" And rpt = 0 Then
- 'SELECIONA A ABA
- sheet.Select
- aba = sheet.Name
- 'TRATA AS PLANILHAS QUE NÃO SÃO VESPER
- If sheet.Name <> "Sites_Vesper" Then
- 'ARMAZENA O NOME DA PLANILHA
- aba1 = sheet.Name
- 'ENCONTRA A SIGLA DO POP NO BANCO DE DADOS MYSQL
- sigla_pop = acha_sigla_pop(aba1)
- End If 'If sheet.Name <> "Sites_Vesper" Then
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- 'RESETA AS VARIÁVEIS PARA CADA CICLO - UM CICLO NESSE CASO É O INTERVALO ENTRE AS LINHAS PRETAS, QUE REPRESENTAM UM ÚNICO EQUIPAMENTO
- 'O CICLO COMEÇA DA LINHA 4 PORQUE A LINHA 3 É A PRIMEIRA PRETA
- inicio = 4
- ReDim ciclo(0)
- ReDim ciclo_pop(0)
- ReDim mux(0)
- ReDim ciclo_placa(0)
- i = 0
- 'ADICIONA O NOME DO MULTIPLEXADOR AO ARRAY MUX
- mux(0) = Range("C3").Value
- 'AUMENTA O TAMANHO DO ARRAY MUX
- ReDim Preserve mux(UBound(mux) + 1)
- For Each celula In Range("C4:C" & LastRow)
- 'DEFINE OS RANGES DE CADA EQUIPAMENTO (LINHA PRETA) NA PLANILHA
- 'ISSO SIGNIFICA CRIAR UMA ESTRUTURA DE LOOP PARA DA INTERVALO ENTRE LINHAS PRETAS NA PLANILHA
- 'LINHA CORRENTE
- linha = celula.Row
- 'VERIFICA SE A LINHA É PRETA E CASO A PLANILHA SEJA A VESPER, UM NOVO POP É INICIADO
- If celula.Interior.ColorIndex = 1 And sheet.Name = "Sites_Vesper" Then
- aba1 = Range("G" & linha).Value
- sigla_pop = acha_sigla_pop(aba1)
- End If
- 'ENCONTRA A LINHA PRETA E DEFINE O FINAL DO "CICLO" DE UM EQUIPAMENTO
- If celula.Interior.ColorIndex = 1 Then
- fim = linha - 1
- 'ADICIONA O CICLO AO ARRAY CICLO PARA GERAR UMA CADEIA DE LOOPS PARA IDENTIFICAR AS PLACAS, MUXS E POPS (VESPER)
- ciclo(i) = "E" & inicio & ":E" & fim
- ciclo_pop(i) = "I" & inicio & ":I" & fim
- ciclo_placa(i) = "K" & inicio & ":K" & fim
- mux(i + 1) = RemoveSpaces(UCase(Range("C" & linha).Value))
- 'AUMENTA O TAMANHO DOS ARRAYS SEM PERDER OS DADOS
- ReDim Preserve ciclo(UBound(ciclo) + 1)
- ReDim Preserve ciclo_pop(UBound(ciclo_pop) + 1)
- ReDim Preserve mux(UBound(mux) + 1)
- ReDim Preserve ciclo_placa(UBound(ciclo_placa) + 1)
- i = i + 1
- 'REINICIA A VARIAVEL 'INICIO' PARA DAR CONTINUIDADE AO LOOP
- inicio = linha + 1
- End If 'If celula.Interior.ColorIndex = 1 Then
- Next ' For Each celula In Range("C4:C" & LastRow)
- 'APOS IDENTIFICAR TODOS OS CICLOS, FINALIZA COM A ULTIMA LINHA PREENCHIDA DO ARQUIVO
- fim = LastRow
- ciclo(i) = "E" & inicio & ":E" & fim
- ciclo_pop(i) = "I" & inicio & ":I" & fim
- ciclo_placa(i) = "K" & inicio & ":K" & fim
- 'ESSE CICLO PEGA AS INFORMACOES DE CADA PLACA (COLUNA K) PARA IDENTIFICA-LAS CORRETAMENTE
- For i = 0 To UBound(ciclo_placa)
- 'RENOMEIA AS PLACAS DE CADA RANGE
- For Each celula In Range(ciclo_placa(i))
- linha_h = celula.Row
- If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- 'PEGA O NOME DA PLACA
- placa = celula.Value
- placa = UCase(RemoveSpaces((placa)))
- 'ATUALIZA O OBJETO 'PLACAS' COM O NOME DA PLACA E UM SEQUENCIAL PARA IDENTIFICAR QUANTAS PLACAS DO MESMO TIPO EXISTEM NAQUELE EQUIPAMENTO
- For t = 0 To UBound(placas)
- 'PEGA A SEQUENCIA DE CADA PLACA REPETIDA
- If placa = placas(t).nome Then
- placas(t).seq = placas(t).seq + 1
- seq_placa = placas(t).seq
- GoTo encontrado_placa
- End If ' If placa = placas(t).nome Then
- Next ' For t = 0 To UBound(placa)
- 'SO SERA EXECUTADO SE NAO ACHAR PLACA
- 'CASO NÃO EXISTA NENHUMA OCORRENCIA DA PLACA NO OBJETO 'PLACAS', ADICIONA UM NOVO ITEM COM O NOME DA PLACA NOVA
- placas(UBound(placas)).nome = placa
- placas(UBound(placas)).seq = 1
- seq_placa = 1
- ReDim Preserve placas(UBound(placas) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR PLACA
- encontrado_placa:
- 'APOS A PLACA TER SIDO CRIADA OU IDENTIFICADA, CRIA UM NOME PARA A PLACA NOS MOLDES - TIPO_DA_PLACA.MUX_ONDE_SE_ENCONTRA.SEQUENCIAL
- nome_placa_mod = placa & "." & mux(i) & "." & seq_placa
- celula.Value = nome_placa_mod
- 'REINICIA O ARRAY DE PORTAS PARA IDENTICAR AS PORTAS DA PLACA ATUAL
- ReDim portas(0)
- End If ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- 'INICIA A VARIAVEL DAS PORTAS
- porta = ""
- 'VERIFICA SE A EXISTE UMA PORTA ASSOCIADA AQUELA PLACA E SE A CELULA NAO ESTA VAZIA
- If Not IsEmpty(celula.Next.Next.Value) And RemoveSpaces((celula.Next.Next.Value)) <> "" Then
- 'ASSOCIA A PORTA A VARIAVEL
- porta = celula.Next.Next.Value
- porta = UCase(RemoveSpaces((porta)))
- End If
- If porta <> "" Then
- 'PEGA AS PORTAS DA PLACA
- 'ASSOCIA CADA PORTA DAQUELA PLACA AO OBJETO 'PORTAS'
- For t = 0 To UBound(portas)
- If porta = portas(t).nome Then
- portas(t).seq = portas(t).seq + 1
- seq_porta = portas(t).seq
- GoTo achou_porta
- End If
- Next
- 'CASO A PORTA NAO EXISTA, CRIA UMA NOVA ENTRADA
- 'SO SERA EXECUTADO SE NAO ACHAR PORTA
- portas(UBound(portas)).nome = porta
- portas(UBound(portas)).seq = 1
- seq_porta = 1
- ReDim Preserve portas(UBound(portas) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR PORTA
- achou_porta:
- 'CRIA UM IDENTIFICADOR PARA A PORTA NO FORMATO PORTA.SEQUENCIAL
- 'CASO NAO EXISTA A LETRA P NO CAMPO ADICIONA ESSA LETRA AO NOME DA PORTA E GRAVA NA CELULA DA PORTA
- If InStr(1, porta, "P") = 0 Then
- celula.Next.Next.Value = "'" & porta & "." & seq_porta
- Else
- celula.Next.Next.Value = porta & "." & seq_porta
- End If
- 'VARIAVEL PARA VERIFICACAO SE A PORTA ESTA COM A CELULA HACHURADA
- porta_hachurada = celula.Next.Next.Value
- hachu_seq = 1
- End If 'If porta <> "" Then
- 'IF PARA VERIFICAR SE A PORTA ESTA HACHURADA. CASO ESTEJA, E A CELULA ESTEJA VAZIA, PREENCHE O DADO COM A ULTIMA PORTA ENCONTRADA
- If IsEmpty(Range("M" & linha_h)) And RemoveSpaces(Range("M" & linha_h).Value) = "" And (Range("M" & linha_h).Interior.Pattern = 14 Or Range("M" & linha_h).Interior.Pattern = -4162) And Not IsEmpty(Range("C" & linha_h)) And RemoveSpaces(Range("C" & linha_h).Value) <> "" Then
- Range("M" & linha_h).Value = porta_hachurada & "." & hachu_seq
- hachu_seq = hachu_seq + 1
- End If
- Next ' For Each celula In Range(ciclo_placa(i))
- 'REINICIA O ARRAY DE PLACAS
- ReDim placas(0)
- Next ' For i = 0 To UBound(ciclo_placa)
- 'LOOP PARA IDENTIFICAR OS MODENS DO LADO DO POP - COLUNA E
- For i = 0 To UBound(ciclo) 'COLUNA E
- For Each celula In Range(ciclo(i))
- linha = celula.Row
- 'VERIFICA SE A CELULA ESA VAZIA, SE ESTIVER, 'RESETA' OS DADOS DA CELULA. ISSO PRECISA SER FEITO PORQUE MUITAS VEZES A FORMATACAO CONDICIONAL
- 'SOBREPOE OS DADOS REAIS DA CELULA. EX. UMA CELULA ESTÁ COM FUNDO PRETO, MAS DECIDO A FORMATACAO CONDICIONAL ESSE ITEM APARECE BRANCO/VERDE/AMARELO/LARANJA
- If IsEmpty(celula.Value) And RemoveSpaces((celula.Value)) = "" Then
- Range("E" & linha).Select
- Selection.Clear
- ' Range("E" & linha).Font.Bold = False
- End If
- 'FAZ A MESMA VERIFICACAO ACIMA, MAS PARA A PORTA
- If IsEmpty(celula.Next.Value) And RemoveSpaces((celula.Next.Value)) = "" Then
- Range("F" & linha).Select
- Selection.Clear
- ' Range("F" & linha).Font.Bold = False
- End If
- Next 'For Each celula In Range(ciclo(i))
- For Each celula In Range(ciclo(i))
- linha = celula.Row
- 'VERIFICAR SE AMBAS AS CELULAS DA COLUNA 'E' E 'F' NAO ESTAO VAZIAS
- If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And Not IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) <> "" And Range("F" & linha).Font.Color <> Range("E" & linha).Font.Color Then
- 'VERIFICA SE A COR DA FONTE DO EQUIPAMENTO É DIFERENTE DA COR DA PORTA DAQUELE EQUIPAMENTO
- If Range("E" & linha).Font.Color <> 0 And Range("F" & linha).Font.Color = 0 Then
- 'EM CASO POSITIVO, COPIA A COR DA FONTE DO EQUIPAMENTO PARA SUA RESPECTIVA PORTA
- Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
- 'FAZ A VERIFICACAO CONTRARIA - COR DA PORTA = COR DO EQUIPAMENTO
- ElseIf Range("F" & linha).Font.Color <> 0 And Range("E" & linha).Font.Color = 0 Then
- Range("E" & linha).Font.Color = Range("F" & linha).Font.Color
- End If
- End If
- 'VERIFICA SE HÁ UM CIRCUITO ASSOCIADO AQUELE EQUIPAMENTO E SE O EQUIPAMENTO E A PORTA EXISTEM
- If Not IsEmpty(Range("C" & linha).Value) And RemoveSpaces((Range("C" & linha).Value)) <> "" And IsEmpty(Range("E" & linha).Value) And RemoveSpaces((Range("E" & linha).Value)) = "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces((Range("F" & linha).Value)) = "" Then
- 'CASO NAO EXISTA EQUIPAMENTO, É CRIADO O EQUIPAMENTO 'CABO' COM SUA RESPECTIVA PORTA 'PO1'
- Range("E" & linha).Value = "CABO"
- Range("E" & linha).Font.Color = 0
- Range("F" & linha).Value = "PO1"
- Range("F" & linha).Font.Color = 0
- End If
- 'VERIFICA SE EXISTE UM EQUIPAMENTO MAS NAO EXISTE UMA PORTA ASSOCIADA A ELE
- If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" Then
- 'CASO O EQUIPAMENTO SEJA UM ASGA, ADICIONA A PORTA P1 PARA ELE
- If InStr(1, Range("E" & linha).Value, "ASGA") <> 0 Then
- Range("F" & linha).Value = "P1"
- Else
- 'SE NAO FOR UM EQUIPAMENTO ASGA, CRIA A PORTA ESPECIAL 1 - PE1
- Range("F" & linha).Value = "PE1"
- End If
- 'COLOCA A COR DA PORTA IGUAL A DO EQUIPAMENTO
- Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
- End If
- 'NAO SEI PRA QUE ESSE CODIGO ABAIXO FOI COMENTADO.
- ' If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" Then
- '
- ' Range("F" & linha).Value = "PE1"
- ' Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
- '
- ' End If
- 'VERIFICA SE EXISTE O EQUIPAMENTO, SE A PORTA E A PORTA ESTÁ VAZIA E SE O EQUIPAMENTO É UM DM706
- If Not IsEmpty(Range("E" & linha).Value) And RemoveSpaces(Range("E" & linha).Value) <> "" And IsEmpty(Range("F" & linha).Value) And RemoveSpaces(Range("F" & linha).Value) = "" And UCase(Range("E" & linha).Value) = "DM706" Then
- 'CASO SEJA, ADICIONA A PORTA P1 E REPETE A COR PARA O EQUIPAMENTO E PORTA
- Range("F" & linha).Value = "P1"
- Range("F" & linha).Font.Color = Range("E" & linha).Font.Color
- End If
- 'CASO SEJA IDENTIFICADO O ITEM 'CPU64' NA COLUNA I, REMOVE ELE - NAO SERVE PARA NADA
- If RemoveSpaces(UCase(Range("I" & linha).Value)) = "CPU64" Then
- Range("I" & linha).Select
- Selection.Clear
- End If
- 'VERIFICA SE A CELULA DO EQUIPAMENTO NAO ESTA VAZIA
- If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- 'ASSOCIA O EQUIPAMENTO A VARIAVEL MODEM
- modem = UCase(RemoveSpaces(celula.Value))
- 'CASO O EQUIPAMENTO SEJA UM CABO, MUDA O NOME PARA CABO_CLI
- If modem = "CABO" Then
- modem = "CABO_CLI"
- End If
- 'ASSOCIA O NOME DO MODEM AO OBJETO-ARRAY MODENS
- modens(UBound(modens)).nome = modem
- 'SE O EQUIPAMENTO NAO FOR UM CABO, ADICIONA A COR DA FONTE AO OBJETO-ARRAY
- If modem <> "CABO" Then
- modens(UBound(modens)).cor_fonte = celula.Font.Color
- 'EM CASO CONTRARIO, SETA A COR COMO 'AUTOMATICO'
- Else
- modens(UBound(modens)).cor_fonte = 0
- End If
- 'ADICIONA A LINHA DE ONDE AQUELE MODEM VEIO
- modens(UBound(modens)).linha = celula.Row
- 'VERIFICA SE JÁ EXISTE O TIPO DE MODEM NA BASE, EM CASO NEGATIVO, CRIA O MODEM. EM CASO POSITIVO ADICIONA UM SEQUENCIAL PARA DIFERENCIACAO
- For t = 0 To UBound(tipo_modem)
- If tipo_modem(t).nome = modem Then
- GoTo encontrado_tipo_modem
- End If
- Next 'For t = 0 To UBound(tipo_modem)
- 'SO SERA EXECUTADO SE NAO ACHAR
- tipo_modem(UBound(tipo_modem)).nome = modem
- tipo_modem(UBound(tipo_modem)).seq = 1
- ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR
- encontrado_tipo_modem:
- 'AUMENTA O TAMANHO DO ARRAY
- ReDim Preserve modens(UBound(modens) + 1)
- End If ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- Next 'For Each celula In Range(ciclo(i))
- 'FORMATA O TIPO DO MODEM E SUA COR PARA SER INSERIDO NA CELULA
- For K = 0 To (UBound(modens) - 1)
- nome_modem = modens(K).nome
- cor_fonte_modem = modens(K).cor_fonte
- For u = 0 To (UBound(tipo_modem) - 1)
- If tipo_modem(u).nome = nome_modem Then
- seq_modem = tipo_modem(u).seq
- posicao_seq_modem = u
- Exit For
- End If 'If tipo_modem(u).nome = nome_modem Then
- Next 'For u = 0 To (UBound(tipo_modem) - 1)
- 'IDENTIFICA A SIGLA DO CLIENTE A PARTIR DA DESIGNACAO PARA COMPOR O NOME DO MODEM
- circuito_cliente = Range("C" & modens(K).linha).Value
- sigla_cliente = ""
- ' sigla_cliente = detecta(circuito_cliente, arquivo, mux(i))
- If sigla_cliente = "" Then
- sigla_cliente = mux(i)
- End If
- 'GERA O NOME DO MODEM PARA ALTERAR A CELULA
- nome_modem_mod = nome_modem & "." & sigla_cliente & "." & seq_modem
- 'CASO A COR SEJA AUTOMATICA (0) O MODEM SERÁ INSERIDO COM O SEQUENCIAL '1'. SENDO ASSIM PULA A ETAPA DE IDENTIFICAR A COR E SEQUENCIAL DO MODEM (LOGO ABAIX0)
- If cor_fonte_modem = 0 Then
- modens(K).novo_nome = nome_modem_mod
- tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
- GoTo linha_zero
- End If 'If cor_fonte_modem = 0 Then
- 'IDENTIFICA SE JÁ EXISTE O MODEM PELA COR DA FONTE, CASO EXISTA, PEGA O NOME DELE
- For y = 0 To (UBound(modens) - 1)
- If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
- modens(y).novo_nome = nome_modem_mod
- End If 'If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
- Next 'For y = 0 To (UBound(modens) - 1)
- 'ATUALIZA O SEQUENCIAL DO TIPO DO MODEM
- tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
- linha_zero:
- 'ATUALIZA O VALOR DA LINHA DO MODEM
- Range("E" & modens(K).linha).Value = nome_modem_mod
- 'CASO O MODEM SEJA CABO_CLI, CRIA A PORTA OTICA 1 - 'PO1'
- If tipo_modem(posicao_seq_modem).nome = "CABO_CLI" Then
- Range("E" & modens(K).linha).Next.Value = "PO1"
- End If 'If tipo_modem(posicao_seq_modem).nome = "CABO" Then
- Next ' For k = 0 To UBound(modens)
- For Each celula In Range(ciclo(i))
- 'LOOP PARA IDENTIFICAR QUAIS MODENS TEM COR DIFERENTE DA AUTOMATICA E SUAS PORTAS ASSOCIADAS
- 'COLOCA AS CORES DAS PORTAS NOS MODENS!!! (LADO CLIENTE)
- 'VERIFICA SE A COR É DIFERENTE DE 0
- If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
- porta_cliente = celula.Next.Value
- cor_porta_cliente = celula.Next.Font.Color
- cor_encontrada = 0
- 'PROCURA PELA COR NO ARRAY MODENS
- For K = 0 To (UBound(modens) - 1)
- 'CASO ENCONTRE, ASSOCIA O EQUIPAMENTO DA MESMA COR À PORTA ASSOCIADA A ELE
- If modens(K).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
- celula.Value = modens(K).novo_nome
- ' celula.Font.Color = modens(k).cor_fonte
- End If 'If modens(k).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
- Next 'For k = 0 To (UBound(modens) - 1)
- 'IF DE VERIFICACAO DEBUG
- ' If IsEmpty(celula) And RemoveSpaces(celula.Value) = "" Then
- '
- ' laleq1a = 0
- '
- ' End If
- End If 'If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
- Next 'Each celula In Range(ciclo(i))
- 'REINICIA OS MODENS E TIPOS DE MODENS PARA O PROXIMO MULTIPLEXADOR
- ReDim modens(0)
- ReDim tipo_modem(0)
- Next 'For i = 0 To UBound(ciclo)
- For i = 0 To UBound(ciclo_pop) 'CICLO MODENS LADO POP COLUNA I
- 'LOOP QUE FAZ AS MESMAS COISAS DO LOOP ANTERIOR, SÓ QUE DESSA VEZ DO LADO DO CLIENTE, COLUNA I
- For Each celula In Range(ciclo(i))
- linha = celula.Row
- If IsEmpty(celula.Value) And RemoveSpaces((celula.Value)) = "" Then
- Range("I" & linha).Font.Color = 0
- Range("I" & linha).Font.Bold = False
- End If
- If IsEmpty(celula.Next.Value) And RemoveSpaces((celula.Next.Value)) = "" Then
- Range("J" & linha).Font.Color = 0
- Range("J" & linha).Font.Bold = False
- End If
- Next
- For Each celula In Range(ciclo_pop(i))
- linha = celula.Row
- If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- modem = UCase(RemoveSpaces(celula.Value))
- modens(UBound(modens)).nome = modem
- modens(UBound(modens)).cor_fonte = celula.Font.Color
- modens(UBound(modens)).linha = celula.Row
- If modem <> "CPU64" Then
- For t = 0 To UBound(tipo_modem)
- If tipo_modem(t).nome = modem Then
- GoTo encontrado_tipo_modem_pop
- End If
- Next 'For t = 0 To UBound(tipo_modem)
- 'SO SERA EXECUTADO SE NAO ACHAR
- tipo_modem(UBound(tipo_modem)).nome = modem
- tipo_modem(UBound(tipo_modem)).seq = 1
- ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR
- encontrado_tipo_modem_pop:
- ReDim Preserve modens(UBound(modens) + 1)
- End If 'If modem <> "CPU64" Then
- End If ' If Not IsEmpty(celula) And RemoveSpaces(celula.Value) <> "" Then
- Next 'For Each celula In Range(ciclo_pop(i))
- For K = 0 To (UBound(modens) - 1)
- nome_modem = modens(K).nome
- cor_fonte_modem = modens(K).cor_fonte
- For u = 0 To (UBound(tipo_modem) - 1)
- If tipo_modem(u).nome = nome_modem Then
- seq_modem = tipo_modem(u).seq
- posicao_seq_modem = u
- Exit For
- End If 'If tipo_modem(u).nome = nome_modem Then
- Next 'For u = 0 To (UBound(tipo_modem) - 1)
- 'VERIFICA SE O MODEM É UM MOFL4E1, AS PORTAS DELE SAO TRATADAS DE FORMA DIFERENTE
- If nome_modem = "MOFL4E1" Then
- seq_modem = Mid(Range("J" & modens(K).linha).Value, 1, 1)
- End If
- nome_modem_mod = nome_modem & "." & mux(i) & "." & seq_modem
- If cor_fonte_modem = 0 Then
- modens(K).novo_nome = nome_modem_mod
- tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
- GoTo linha_zero_pop
- End If 'If cor_fonte_modem = 0 Then
- For y = 0 To (UBound(modens) - 1)
- If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
- modens(y).novo_nome = nome_modem_mod
- End If 'If nome_modem = modens(y).nome And cor_fonte_modem = modens(y).cor_fonte And modens(y).cor_fonte <> 0 And modens(y).novo_nome = "" Then
- Next 'For y = 0 To (UBound(modens) - 1)
- tipo_modem(posicao_seq_modem).seq = tipo_modem(posicao_seq_modem).seq + 1
- linha_zero_pop:
- Range("I" & modens(K).linha).Value = nome_modem_mod
- 'CASO O MODEM SEJA UM CABO_POP, CRIA UMA PORTA OTICA 1 PARA ELE PO1
- If tipo_modem(posicao_seq_modem).nome = "CABO_POP" Then
- Range("I" & modens(K).linha).Next.Value = "PO1"
- End If 'If tipo_modem(posicao_seq_modem).nome = "CABO" Then
- Next ' For k = 0 To UBound(modens)
- For Each celula In Range(ciclo_pop(i))
- linha_plan = celula.Row
- 'VERIFICA SE A LINHA ACIMA DA LINHA ATUAL É PRETA E SE A PLANILHA É VESPER. EM CASO POSITIVO PEGA A SIGLA DO POP
- If Range("C" & linha_plan - 1).Interior.ColorIndex = 1 And sheet.Name = "Sites_Vesper" Then
- aba1 = Range("G" & linha_plan - 1).Value
- sigla_pop = acha_sigla_pop(aba1)
- End If
- 'PEGA OS DADOS DA CELULA PARA GERAR O HYPERLINK
- subend = ("'" & aba & "'!" & RemoveDolars(celula.Address))
- 'strcell = celula.Address
- linha_preta = 0
- 'RESETA AS VARIAVEIS QUE SAO UTILIZADAS QUANDO O MODEM É FLEX
- nome_flex = ""
- numero_flex = ""
- slot_flex = ""
- porta_flex = ""
- 'VERIFICA SE A PORTA ESTÁ PREENCHIDA, SE A COR DA FONTE É DIFERENTE DE 0 E SE NÃO EXISTEM OS CARACTERES ESPECIAIS '-' E '/' NA PORTA
- If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 And InStr(celula.Next.Value, "/") = 0 And InStr(celula.Next.Value, "-") = 0 Then
- 'PEGA OS DADOS DAS PORTAS DO EQUIPAMENTO DO CLIENTE
- porta_cliente = celula.Next.Value
- cor_porta_cliente = celula.Next.Font.Color
- 'VERIFICA SE A COR JÁ FOI UTILIZADA EM ALGUM MODEM ANTERIOR AO ATUAL
- For K = 0 To (UBound(modens) - 1)
- If modens(K).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
- celula.Value = modens(K).novo_nome
- End If 'If modens(k).cor_fonte = cor_porta_cliente And (IsEmpty(celula) Or RemoveSpaces(celula.Value) = "") Then
- Next 'For k = 0 To (UBound(modens) - 1)
- 'CASO A PORTA TENHA '/' OU '-' ELA É DE UM MODEM FLEX
- ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") = 0 And countSeparators(celula.Next.Value, "/") < 2 Then
- 'SEPARA AS INFORMAÇÕES DA PORTA DO MODEM FLEX
- celula.Select
- celula.Next.Select
- celula.Next.Font.Color = 0
- nome_flex = "MOFL4E1"
- numero_flex = Mid(celula.Next.Value, 1, InStr(1, celula.Next.Value, "/") - 2)
- slot_flex = Mid(celula.Next.Value, 2, InStr(1, celula.Next.Value, "/") - 2)
- porta_flex = "P" & Mid(celula.Next.Value, InStr(1, celula.Next.Value, "/") + 1, Len(celula.Next.Value))
- celula.Value = nome_flex & "." & mux(i) & "." & numero_flex
- ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") <> 0 And countSeparators(celula.Next.Value, "/") < 2 Then
- 'CASO NAO SEJA UM MODEM FLEX, A PORTA É DE UM MODEM AX4E1
- celula.Next.Value = UCase(RemoveSpaces((celula.Next.Value)))
- celula.Next.Font.Color = 0
- nome_flex = "MOAX4E1"
- tira_mux = Mid(celula.Next.Value, InStr(1, celula.Next.Value, "-") + 1, Len(celula.Next.Value))
- numero_flex = Mid(tira_mux, 1, 1)
- tira_numero = Mid(tira_mux, InStr(1, tira_mux, "S"), Len(tira_mux))
- slot_flex = Mid(tira_numero, 1, InStr(1, tira_numero, "/") - 1)
- tira_slot = Mid(tira_numero, InStr(1, tira_numero, "/") + 1, Len(tira_numero))
- interface = Mid(tira_slot, 1, InStr(1, tira_slot, "P") - 1)
- slot_flex = slot_flex & "/" & interface
- porta_flex = Mid(tira_slot, InStr(1, tira_slot, interface) + 1, Len(tira_slot))
- celula.Value = nome_flex & "." & mux(i) & "." & numero_flex
- 'CASO A PORTA NAO SEJA NEM DE UM MODEM FLEX, NEM DE UM AX4E1, É DE UM MDOEM DM4E1S
- ElseIf InStr(celula.Next.Value, "/") <> 0 And InStr(celula.Next.Value, "-") = 0 And countSeparators(celula.Next.Value, "/") = 2 Then
- numero_dm4 = Mid(celula.Next.Value, 1, InStr(1, celula.Next.Value, "/") - 1)
- slot_porta = Mid(celula.Next.Value, InStr(1, celula.Next.Value, "/") + 1, Len(celula.Next.Value))
- celula.Value = "DM4E1S." & mux(i) & "." & numero_dm4
- celula.Next.Value = "'" & slot_porta
- End If 'If Not IsEmpty(celula.Next) And RemoveSpaces(celula.Next.Value) <> "" And celula.Next.Font.Color <> 0 Then
- 'AUMENTA EM 1 A CONTAGEM DA LINHA PRETA PARA O PROXIMO LOOP
- If celula.Interior.ColorIndex = 1 Then
- linha_preta = linha_preta + 1
- End If
- If Not IsEmpty(Range("L" & linha_plan).Value) And RemoveSpaces(Range("L" & linha_plan).Value) <> "" Then
- 'PEGA O VALOR DA CELULA QUE CONTEM O SLOT
- slot_plan = Range("L" & linha_plan).Value
- End If
- If Not IsEmpty(Range("K" & linha_plan).Value) And RemoveSpaces(Range("K" & linha_plan).Value) <> "" Then
- 'PEGA O VALOR DA CELULA QUE CONTEM A PLACA
- placa_plan = Range("K" & linha_plan).Value
- End If
- 'VERIFICA SE EXISTE UM CIRCUITO EXISTE E ESTE NÃO ESTÁ VAZIO
- If Not IsEmpty(Range("C" & linha_plan).Value) And RemoveSpaces((Range("C" & linha_plan).Value)) <> "" Then
- circuito_plan = Range("C" & linha_plan).Value
- pop_mux_plan = sigla_pop
- nome_mux_plan = mux(i)
- tipo_mux_plan = acha_tipo_equip(nome_mux_plan)
- If tipo_mux_plan = "99" Then
- subend_erro = ("'" & aba & "'!" & RemoveDolars(celula.Address))
- 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, celula.Value, "Erro - Tipo de Multiplexador não identificado : " & nome_mux_plan)
- vazia = 1
- End If
- 'PEGA OS DADOS DA PORTA DO MUX - COLUNA M
- If Not IsEmpty(Range("M" & linha_plan).Value) And RemoveSpaces(Range("M" & linha_plan).Value) <> "" Then
- porta_mux_plan = Range("M" & linha_plan).Value
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("M" & linha_plan).Address))
- 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("M" & linha_plan).Value, "Porta do Multiplexador não encontrada.")
- vazia = 1
- End If
- 'PEGA OS DADOS DO MODEM DO LADO DO POP
- If Not IsEmpty(Range("I" & linha_plan).Value) And RemoveSpaces(Range("I" & linha_plan).Value) <> "" Then
- modem_pop_plan = Range("I" & linha_plan).Value
- tipo_modem_pop_plan = Mid(modem_pop_plan, 1, InStr(1, modem_pop_plan, ".") - 1)
- Else
- 'CASO ESTEJA VAZIO, CRIA-SE O CABO_POP
- modem_pop_plan = "CABO_POP"
- tipo_modem_pop_plan = "CABO_POP"
- 'VALIDA O TIPO DE MODEM DO LADO DO POP E CASO EXISTA, ADICIONA UM SEQUENCIAL A ELE
- For t = 0 To UBound(tipo_modem)
- If tipo_modem(t).nome = modem_pop_plan Then
- tipo_modem(t).seq = tipo_modem(t).seq + 1
- seq_modem_vazio = tipo_modem(t).seq
- GoTo encontrado_tipo_modem_pop_vazio
- End If
- Next 'For t = 0 To UBound(tipo_modem)
- 'SO SERA EXECUTADO SE NAO ACHAR
- 'CRIA UM NOVO TIPO DE MODEM CASO NENHUM SEJA ENCONTRADO
- tipo_modem(UBound(tipo_modem)).nome = modem_pop_plan
- tipo_modem(UBound(tipo_modem)).seq = 1
- seq_modem_vazio = 1
- ReDim Preserve tipo_modem(UBound(tipo_modem) + 1)
- 'SO SERA EXECUTADO SE NAO ACHAR
- encontrado_tipo_modem_pop_vazio:
- modem_pop_plan = modem_pop_plan & "." & mux(i) & "." & seq_modem_vazio
- End If
- 'CASO O MODEM SEJA FLEX OU AX4E1, A PORTA DO MODEM DO CLIENTE É A VARIAVEL 'slot_flex' E A PORTA DO LADO DO POP É PO1
- If tipo_modem_pop_plan = "MOFL4E1" Or tipo_modem_pop_plan = "MOAX4E1" Then
- porta_modem_pop_cliente = slot_flex
- porta_modem_cliente_pop = "PO1"
- Else
- 'CASO CONTRARIO AMBAS AS PORTAS DO LADO DO CLIENTE E DO POP SÃO PORTAS OTICAS (PO1)
- porta_modem_pop_cliente = "PO1"
- porta_modem_cliente_pop = "PO1"
- End If
- 'CASO NAO EXISTA UMA PORTA DE MODEM FLEX E A COLUNA J (PORTA DO LADO DO POP) NAO ESTEJA VAZIA,
- If porta_flex = "" And Not IsEmpty(Range("J" & linha_plan).Value) And RemoveSpaces(Range("J" & linha_plan).Value) <> "" Then
- porta_pop_plan = Range("J" & linha_plan).Value
- 'CASO EXISTA UMA PORTA FLEX, PEGA-SE O VALOR DELA
- ElseIf porta_flex <> "" Then
- porta_pop_plan = porta_flex & "-" & slot_flex
- 'CASO O MODEM SEJA CABO_POP, CRIA-SE A PORTA 'PE1'
- ElseIf tipo_modem_pop_plan = "CABO_POP" Then
- porta_pop_plan = "PE1"
- ElseIf tipo_modem_pop_plan = "CONV" Then
- porta_pop_plan = "PE1"
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("F" & linha_plan).Address))
- 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("F" & linha_plan).Value, "Porta do não modem(POP) encontrada.")
- vazia = 1
- End If
- 'CASO O MODEM DO CLIENTE NAO ESTEJA VAZIO, PEGA OS DADOS DELE
- If Not IsEmpty(Range("E" & linha_plan).Value) And RemoveSpaces(Range("E" & linha_plan).Value) <> "" Then
- modem_cliente_plan = Range("E" & linha_plan).Value
- tipo_modem_cliente_plan = Mid(modem_cliente_plan, 1, InStr(1, modem_cliente_plan, ".") - 1)
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("E" & linha_plan).Address))
- 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("E" & linha_plan).Value, "Modem do cliente não encontrado.")
- vazia = 1
- End If
- 'CASO O MODEM DO CLIENTE EXISTA E A COLUNA F NAO ESTEJA VAZIA, PEGA-SE OS DADOS DA PORTA DO CLIENTE DA COLUNA F
- If Not IsEmpty(Range("E" & linha_plan).Value) And RemoveSpaces(Range("E" & linha_plan).Value) <> "" And Not IsEmpty(Range("F" & linha_plan).Value) And RemoveSpaces(Range("F" & linha_plan).Value) <> "" Then
- porta_cli_plan = Range("F" & linha_plan).Value
- 'CASO O MODEM SEJA CABO_CLI, CRIA-SE A PORTA 'P01'
- ElseIf tipo_modem_cliente_plan = "CABO_CLI" Then
- porta_cli_plan = "PO1"
- ElseIf tipo_modem_cliente_plan = "CONV" Then
- porta_cli_plan = "PE1"
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("F" & linha_plan).Address))
- 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("F" & linha_plan).Value, "Porta do modem (CLI) não encontrada.")
- vazia = 1
- End If
- 'CASO A COLUNA N ESTEJA PREENCHIDA, PEGA-SE OS DADOS DA OPERADORA DELA
- If Not IsEmpty(Range("N" & linha_plan).Value) And RemoveSpaces(Range("N" & linha_plan).Value) <> "" Then
- operadora_plan = Range("N" & linha_plan).Value
- End If
- 'CASO A COLUNA O ESTEJA PREENCHIDA, PEGA-SE OS DADOS DA OS DELA
- If Not IsEmpty(Range("O" & linha_plan).Value) And RemoveSpaces(Range("O" & linha_plan).Value) <> "" Then
- os_plan = Range("O" & linha_plan).Value
- End If
- 'CASO A COLUNA B ESTEJA PREENCHIDA, PEGA-SE OS DADOS DO STATUS DO CIRCUITO DELA
- If Not IsEmpty(Range("B" & linha_plan)) And RemoveSpaces(Range("B" & linha_plan).Value) <> "" Then
- status_circuito = Range("B" & linha_plan).Value
- Else
- subend_erro = ("'" & aba & "'!" & RemoveDolars(Range("B" & linha_plan).Address))
- 'retorno_erro = 'erro(plan_erro, arquivo, end2, subend_erro, Range("B" & linha_plan).Value, "Status do circuito não encontrado.")
- vazia = 1
- End If
- End If
- If modem_cliente_plan = "" Then
- Windows(arquivo).Activate
- porta_mod_cli = Range("F" & linha_plan).Value
- cor_porta_mod_cli = Range("F" & linha_plan).Font.Color
- end_mod_cli = Range("H" & linha_plan).Value
- end_mod_cli = RemoveSpaces(UCase(end_mod_cli))
- If cor_porta_mod_cli <> 0 Then
- For Each celula_mod_cli In Range("C4:C" & LastRow)
- linha_mod_cli = celula_mod_cli.Row
- If (Range("F" & linha_mod_cli).Font.Color = cor_porta_mod_cli) And (end_mod_cli = RemoveSpaces(UCase(Range("H" & linha_mod_cli).Value))) And (linha_mod_cli <> linha_plan) Then
- modem_cliente_plan = Range("E" & linha_mod_cli).Value
- porta_cli_plan = porta_mod_cli
- tipo_modem_cliente_plan = Mid(modem_cliente_plan, 1, InStr(1, modem_cliente_plan, ".") - 1)
- Exit For
- End If
- Next 'For Each CELULA_MOD_CLI In Range("C4:C" & lastrow)
- End If
- 'Windows(nova).Activate
- End If
- Next 'Each celula In Range(ciclo_pop(i))
- ReDim modens(0)
- ReDim tipo_modem(0)
- Next 'For i = 0 To UBound(ciclo_pop)
- End If ' If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- 'AO FIM DE CADA ABA, VERIFICA SE HÁ A NECESSIDADE DE REORGANIZAR AS PORTAS DOS DM705
- rodada = 0
- Next ' For Each sheet In ActiveWorkbook.Worksheets
- Windows(arquivo).Activate
- 'FECHA O ARQUIVO DE FACILIDADES
- ' Windows(arquivo).Close False
- ' Next ' For sasa = LBound(Filename) To UBound(Filename) ' FOR abre arquivos
- 'VOLTA A ATUALIZAR A TELA
- 'Application.ScreenUpdating = True
- sicop = 0
- End Function
- Public Function letra_func(ByVal valor As String) As String
- If Len(Trim(valor)) = 3 Then
- If InStr(1, valor, "A") <> 0 Then
- letra = Mid(valor, 1, 1)
- GoTo acha_letra
- End If
- If InStr(1, valor, "B") <> 0 Then
- letra = Mid(valor, 1, 1)
- GoTo acha_letra
- End If
- If InStr(1, valor, "C") <> 0 Then
- letra = Mid(valor, 1, 1)
- GoTo acha_letra
- End If
- If InStr(1, valor, "D") <> 0 Then
- letra = Mid(valor, 1, 1)
- GoTo acha_letra
- End If
- If InStr(1, valor, "E") <> 0 Then
- letra = Mid(valor, 1, 1)
- GoTo acha_letra
- End If
- If InStr(1, valor, "F") <> 0 Then
- letra = Mid(valor, 1, 1)
- GoTo acha_letra
- End If
- If InStr(1, valor, "G") <> 0 Then
- letra = Mid(valor, 1, 1)
- GoTo acha_letra
- End If
- If InStr(1, valor, "H") <> 0 Then
- letra = Mid(valor, 1, 1)
- GoTo acha_letra
- End If
- End If
- letra = valor
- acha_letra:
- letra_func = letra
- End Function
- Function checa_canalizado(ByVal velocidade As String) As Integer
- velocidade = RemoveSpaces(UCase(velocidade))
- Select Case (velocidade)
- Case "1M"
- checa_canalizado = 1
- Case "64K"
- checa_canalizado = 1
- Case "128K"
- checa_canalizado = 1
- Case "192K"
- checa_canalizado = 1
- Case "256K"
- checa_canalizado = 1
- Case "320K"
- checa_canalizado = 1
- Case "384K"
- checa_canalizado = 1
- Case "448K"
- checa_canalizado = 1
- Case "512K"
- checa_canalizado = 1
- Case "576K"
- checa_canalizado = 1
- Case "640K"
- checa_canalizado = 1
- Case "704K"
- checa_canalizado = 1
- Case "768K"
- checa_canalizado = 1
- Case "832K"
- checa_canalizado = 1
- Case "896K"
- checa_canalizado = 1
- Case "960K"
- checa_canalizado = 1
- Case "1024K"
- checa_canalizado = 1
- Case "1088K"
- checa_canalizado = 1
- Case "1152K"
- checa_canalizado = 1
- Case "1216K"
- checa_canalizado = 1
- Case "1280K"
- checa_canalizado = 1
- Case "1344K"
- checa_canalizado = 1
- Case "1408K"
- checa_canalizado = 1
- Case "1472K"
- checa_canalizado = 1
- Case "1536K"
- checa_canalizado = 1
- Case "1600K"
- checa_canalizado = 1
- Case "1664K"
- checa_canalizado = 1
- Case "1728K"
- checa_canalizado = 1
- Case "1792K"
- checa_canalizado = 1
- Case "1856K"
- checa_canalizado = 1
- Case "1920K"
- checa_canalizado = 1
- Case "1984K"
- checa_canalizado = 1
- Case Else
- checa_canalizado = 0
- End Select
- End Function
- Public Function LastColumnInOneRow(ByVal linha As Integer) As String
- 'Find the last used column in a Row: row 1 in this example
- Dim LastCol As Integer
- With ActiveSheet
- LastCol = .Cells(linha, .Columns.Count).End(xlToLeft).Column
- End With
- LastColumnInOneRow = LastCol
- End Function
- Public Function procura_next(ByVal prox_equip As String, ByVal coluna_atual As String, ByVal linha As Integer, ByVal ultima_coluna As String) As String
- For i = 3 To ultima_coluna
- If i Mod 2 = 1 Then
- coluna = ConvertToLetter(i)
- If coluna <> coluna_atual Then
- facilidade = Range(ConvertToLetter(i) & linha).Value
- comeco = Mid(facilidade, 1, InStr(1, facilidade, " ") - 1)
- intermed = Mid(facilidade, InStr(1, facilidade, " ") + 1, Len(facilidade))
- fim = Mid(intermed, 1, InStr(1, intermed, " ") - 1)
- equip1 = Mid(comeco, 4, Len(comeco))
- equip2 = Mid(fim, 4, Len(fim))
- If InStr(1, equip1, prox_equip) <> 0 Then
- procura_next = coluna & "." & equip2
- ElseIf InStr(1, equip2, prox_equip) <> 0 Then
- procura_next = coluna & "." & equip1
- End If
- End If 'If coluna <> coluna_atual Then
- End If
- Next
- If procura_next = "" Then
- procura_next = 0
- End If
- End Function
- Public Function ordena_swap(array_canalizados() As String, ByVal linha As String) As Integer
- Dim array_canal() As array_canal
- ReDim Preserve array_canal(0)
- For i = 1 To UBound(array_canalizados)
- coluna_canal = array_canalizados(i - 1)
- coluna_ts = ConvertToLetter(ConvertToNumber(coluna_canal) + 1)
- array_canal(UBound(array_canal)).facilidade = Range(coluna_canal & linha).Value
- array_canal(UBound(array_canal)).ts = Range(coluna_ts & linha).Value
- ReDim Preserve array_canal(UBound(array_canal) + 1)
- Next
- j = 1
- For i = 1 To UBound(array_canal)
- coluna_insert_canal = ConvertToLetter(j + 2)
- coluna_insert_ts = ConvertToLetter(j + 3)
- Range(coluna_insert_canal & linha).Value = array_canal(i - 1).facilidade
- Range(coluna_insert_ts & linha).Value = "'" & array_canal(i - 1).ts
- j = j + 2
- Next
- End Function
- Function ConvertToNumber(ByVal Col As String) As Integer
- 'Function ColRef(Col As String) As Integer
- Col = UCase(Col)
- If Len(Col) = 1 Then
- ConvertToNumber = Asc(Col) - 64
- ElseIf Len(Col) = 2 Then
- C1 = Left$(Col, 1)
- ColRef1 = (Asc(C1) - 64) * 26
- C2 = Right$(Col, 1)
- ConvertToNumber = ColRef1 + (Asc(C2) - 64)
- End If
- ' If (ConvertToNumber <> 256) Then
- ' MsgBox "Wrong Column number", vbExclamation
- ' ConvertToNumber = -1
- ' Exit Function
- ' End If
- End Function
- Public Type arrei
- cidade As String
- range1 As Integer
- range2 As Integer
- range3 As Integer
- range4 As Integer
- range5 As Integer
- End Type
- Dim conn As ADODB.Connection
- Dim rs As ADODB.Recordset
- Dim arrei() As arrei
- Dim cancela As String
- Private Sub ConnectDB()
- Set conn = New ADODB.Connection
- conn.Open "DRIVER={MySQL ODBC 5.2 ANSI Driver};" & _
- "SERVER=mysql.infovias.unix.corp;" & _
- "DATABASE=sici;" & _
- "USER=sici;" & _
- "PASSWORD=sici;" & _
- "Option=3"
- End Sub
- Public Sub auto_open()
- Cells.Clear
- Set rs = New ADODB.Recordset
- ConnectDB
- ' GoTo formulario '###DEBUG
- rs.ActiveConnection = conn
- rs.LockType = adLockOptimistic
- rs.CursorLocation = adUseClient
- rs.CursorType = adOpenDynamic
- Dim sheet As Worksheet
- Dim celula, celula1 As Range
- Dim LastRow As Long
- Dim Filter As String
- Dim FilterIndex As Integer
- Dim Filename As Variant
- Dim remove As String
- ReDim Preserve arrei(0)
- ' UserForm1.ComboBox1.List = Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
- ' UserForm1.ComboBox2.List = Array("2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020")
- ' UserForm1.Show
- '
- ' If UserForm1.Label2.Caption = "Cancelado" Then
- ' retorno_user = MsgBox("Processo cancelado!", , "INFO")
- ' UserForm1.Label2.Caption = ""
- ' UserForm1.ComboBox1.Value = ""
- ' UserForm1.ComboBox2.Value = ""
- ' Exit Sub
- ' End If
- '
- ' select_envio = "select id_envio from sici_envio where referencia_mes = '" & CInt(UserForm1.ComboBox1.Value) & "' and referencia_ano = '" & CInt(UserForm1.ComboBox2.Value) & "'"
- ' rs.Open select_envio, conn
- '
- ' If rs.BOF = False Then
- '
- ' competencia = UserForm1.ComboBox1.Value & " / " & UserForm1.ComboBox2.Value
- ' pergunta = MsgBox("Já existem informações no banco da competência " & competencia & ". Deseja SOBRESCREVER?", vbYesNo, "Confirma?")
- '
- ' If pergunta = vbYes Then
- ' id_envio = rs!id_envio
- ' rs.Close
- ' delete_cidade_envio = "delete from sici_cidade_envio where id_envio = " & id_envio
- ' rs.Open delete_cidade_envio, conn
- ' delete_indicador_item = "delete from sici_indicador_item where id_envio = " & id_envio
- ' rs.Open delete_indicador_item, conn
- '
- ' Else
- ' retorno_user = MsgBox("Processo cancelado!", , "INFO")
- ' Exit Sub
- ' End If
- '
- ' If rs.State = adStateOpen Then
- ' rs.Close
- ' End If
- '
- '
- ' Else
- ' rs.Close
- ' insert_envio = "insert into sici_envio values (''," & CInt(UserForm1.ComboBox1.Value) & "," & CInt(UserForm1.ComboBox2.Value) & ",'',null)"
- ' rs.Open insert_envio, conn
- ' select_id_envio = "select max(id_envio) as id_envio from sici_envio"
- ' rs.Open select_id_envio, conn
- ' id_envio = rs!id_envio
- ' rs.Close
- '
- ' End If
- Application.ScreenUpdating = False
- ' File filters
- Filter = "Excel Files (*.xls),*.xls," & _
- "Text Files (*.txt),*.txt," & _
- "All Files (*.*),*.*"
- ' Default filter to *.*
- FilterIndex = 3
- ' Set Dialog Caption
- Title = "Favor selecionar os arquivos do controle de facilidades "
- ' Select Start Drive & Path
- ChDrive ("C")
- ChDir ("C:\Users\acunha\Desktop\Trabalho\Engenharia\Facilidades")
- With Application
- ' Set File Name Array to selected Files (allow multiple)
- Filename = .GetOpenFilename(Filter, FilterIndex, Title, , True)
- ' Reset Start Drive/Path
- ChDrive (Left(.DefaultFilePath, 1))
- ChDir (.DefaultFilePath)
- End With
- ' Exit on Cancel
- If Not IsArray(Filename) Then
- MsgBox "Nenhum arquivo selecionado."
- Exit Sub
- End If
- principal = ActiveWorkbook.Name
- ' Workbooks.Add
- ' ActiveWorkbook.Activate
- ' nova = ActiveWorkbook.Name
- ' Open Files
- For sasa = LBound(Filename) To UBound(Filename) ' FOR abre arquivos
- msg = msg & Filename(sasa) & vbCrLf ' This can be removed
- Workbooks.Open Filename(sasa), False
- arquivo = ActiveWorkbook.Name
- Windows(arquivo).Activate
- For Each sheet In ActiveWorkbook.Worksheets
- If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" And sheet.Name <> "Sites_Vesper" Then
- sheet.Select
- aba = sheet.Name
- cidade = acha_cidade(aba)
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- For Each celula In Range("C4:C" & LastRow)
- If Not IsEmpty(celula.Value) And RemoveSpaces(celula.Value) <> "" And celula.Interior.ColorIndex <> 1 Then
- linha = celula.Row
- designacao = Range("C" & linha).Value
- velocidade = Range("D" & linha).Value
- Select Case velocidade
- Case "2M"
- retorno = insere_velo(cidade, 2)
- Case "0"
- retorno = insere_velo(cidade, 6)
- Case "1"
- retorno = insere_velo(cidade, 6)
- Case "2"
- retorno = insere_velo(cidade, 6)
- Case "3"
- retorno = insere_velo(cidade, 6)
- Case "4"
- retorno = insere_velo(cidade, 6)
- Case "5"
- retorno = insere_velo(cidade, 6)
- Case "6"
- retorno = insere_velo(cidade, 6)
- Case "7"
- retorno = insere_velo(cidade, 6)
- Case "8"
- retorno = insere_velo(cidade, 6)
- Case "9"
- retorno = insere_velo(cidade, 6)
- Case "10"
- retorno = insere_velo(cidade, 6)
- Case "11"
- retorno = insere_velo(cidade, 6)
- Case "12"
- retorno = insere_velo(cidade, 6)
- Case "13"
- retorno = insere_velo(cidade, 6)
- Case "14"
- retorno = insere_velo(cidade, 6)
- Case "16"
- retorno = insere_velo(cidade, 6)
- Case "17"
- retorno = insere_velo(cidade, 6)
- Case "18"
- retorno = insere_velo(cidade, 6)
- Case "19"
- retorno = insere_velo(cidade, 6)
- Case "20"
- retorno = insere_velo(cidade, 6)
- Case "21"
- retorno = insere_velo(cidade, 6)
- Case "22"
- retorno = insere_velo(cidade, 6)
- Case "26"
- retorno = insere_velo(cidade, 6)
- Case "27"
- retorno = insere_velo(cidade, 6)
- Case "29"
- retorno = insere_velo(cidade, 6)
- Case "30"
- retorno = insere_velo(cidade, 6)
- Case "44"
- retorno = insere_velo(cidade, 6)
- Case "54"
- retorno = insere_velo(cidade, 6)
- Case "57"
- retorno = insere_velo(cidade, 6)
- Case "58"
- retorno = insere_velo(cidade, 6)
- Case "59"
- retorno = insere_velo(cidade, 6)
- Case "100M"
- retorno = insere_velo(cidade, 5)
- Case "10M"
- retorno = insere_velo(cidade, 3)
- Case "128K"
- retorno = insere_velo(cidade, 1)
- Case "155M"
- retorno = insere_velo(cidade, 5)
- Case "1984K"
- retorno = insere_velo(cidade, 2)
- Case "1M"
- retorno = insere_velo(cidade, 2)
- Case "20M"
- retorno = insere_velo(cidade, 4)
- Case "256K"
- retorno = insere_velo(cidade, 1)
- Case "256k "
- retorno = insere_velo(cidade, 1)
- Case "2M"
- retorno = insere_velo(cidade, 2)
- Case "2M "
- retorno = insere_velo(cidade, 2)
- Case "32M"
- retorno = insere_velo(cidade, 4)
- Case "34M"
- retorno = insere_velo(cidade, 4)
- Case "40M"
- retorno = insere_velo(cidade, 5)
- Case "45M"
- retorno = insere_velo(cidade, 5)
- Case "48M"
- retorno = insere_velo(cidade, 5)
- Case "4M"
- retorno = insere_velo(cidade, 3)
- Case "50M"
- retorno = insere_velo(cidade, 5)
- Case "512K"
- retorno = insere_velo(cidade, 1)
- Case "5M"
- retorno = insere_velo(cidade, 3)
- Case "64K"
- retorno = insere_velo(cidade, 1)
- Case "6M"
- retorno = insere_velo(cidade, 3)
- Case "768K"
- retorno = insere_velo(cidade, 2)
- Case "80M"
- retorno = insere_velo(cidade, 5)
- Case "84M"
- retorno = insere_velo(cidade, 5)
- Case "8M"
- retorno = insere_velo(cidade, 3)
- Case "960k"
- retorno = insere_velo(cidade, 1)
- End Select
- Windows(principal).Activate
- If WorksheetFunction.CountA(Cells) > 0 Then
- 'Search for any entry, by searching backwards by Rows.
- LastRow3 = Cells.Find(What:="*", After:=[A1], _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlPrevious).Row
- End If
- Range("A" & LastRow3 + 1).Value = designacao
- Range("B" & LastRow3 + 1).Value = velocidade
- Range("C" & LastRow3 + 1).Value = cidade
- Windows(arquivo).Activate
- End If ' If Not IsEmpty(celula.Value) And RemoveSpaces(celula.Value) <> "" Then
- Next ' For Each celula In Range("A3:A" & LastRow)
- End If ' If sheet.Name <> "Índice" And sheet.Name <> "Sites_interior" And sheet.Name <> "Sites" Then
- Next ' For Each sheet In ActiveWorkbook.Worksheets
- Windows(arquivo).Close False
- Next ' For sasa = LBound(Filename) To UBound(Filename) ' FOR abre arquivos
- Windows(principal).Activate
- Application.ScreenUpdating = True
- End Sub
- Public Function insere_velo(ByVal cidade As String, ByVal posicao As Integer)
- If posicao = 6 Then
- Exit Function
- End If
- Achou = 0
- For i = 0 To UBound(arrei)
- If arrei(i).cidade = cidade Then
- Select Case posicao
- Case 1
- arrei(i).range1 = arrei(i).range1 + 1
- Exit Function
- Case 2
- arrei(i).range2 = arrei(i).range2 + 1
- Exit Function
- Case 3
- arrei(i).range3 = arrei(i).range3 + 1
- Exit Function
- Case 4
- arrei(i).range4 = arrei(i).range4 + 1
- Exit Function
- Case 5
- arrei(i).range5 = arrei(i).range5 + 1
- Exit Function
- End Select
- Achou = 1
- End If
- Next
- If Achou = 0 Then
- arrei(UBound(arrei)).cidade = cidade
- Select Case posicao
- Case 1
- arrei(UBound(arrei)).range1 = 1
- Case 2
- arrei(UBound(arrei)).range2 = 1
- Case 3
- arrei(UBound(arrei)).range3 = 1
- Case 4
- arrei(UBound(arrei)).range4 = 1
- Case 5
- arrei(UBound(arrei)).range5 = 1
- End Select
- ReDim Preserve arrei(UBound(arrei) + 1)
- End If
- End Function
- Public Function acha_cidade(ByVal plan As String)
- If rs.State = adStateOpen Then
- rs.Close
- End If
- select_plan = "select c.nome_cidade as nome from pop p join cidade c on p.id_cidade = c.id_cidade where p.nome_pop = '" & plan & "'"
- rs.Open select_plan
- If rs.BOF = False Then
- acha_cidade = rs!nome
- rs.Close
- Else
- MsgBox (plan)
- End If
- End Function
- Public Function RemoveSpaces(strInput As String)
- ' Removes all spaces from a string of text
- Test:
- If InStr(strInput, " ") = 0 Then
- RemoveSpaces = strInput
- Else
- strInput = Left(strInput, InStr(strInput, " ") - 1) _
- & Right(strInput, Len(strInput) - InStr(strInput, " "))
- GoTo Test
- End If
- End Function
- Public Function checa_cor(linha As Integer, coluna As Integer)
- If Cells(linha, coluna).Interior.ColorIndex <> 1 Or Cells(linha, (coluna - 1)).Interior.ColorIndex <> 1 Or Cells(linha, (coluna + 1)).Interior.ColorIndex <> 1 Then
- checa_cor = 0
- Else
- checa_cor = 1
- End If 'If Cells(linha, coluna).Interior.ColorIndex <> 1 Or Cells(linha, (coluna - 1)).Interior.ColorIndex <> 1 Or Cells(linha, (coluna + 1)).Interior.ColorIndex <> 1 Then
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement