Pessoal, bom dia! Poderiam me dar uma ajuda?
Eu tenho o código abaixo que utilizo no access para preencher um arquivo word através de informações do banco de dados, tudo estava funcionando perfeitamente até incluírem no modelo campos que estão dentro de caixas de textos. Ocorre que agora não consigo localizar as informações que estão dentro de caixas de textos para substituir.
Segue código abaixo, a parte que está como comentário é justamente a parte em que os campos estão dentro de caixas de textos.
Public Function Fncmesclar()
On Error GoTo TrataErro
Dim strLocal As String
Dim WORD As WORD.Application
Dim DOC As WORD.Document
Set WORD = CreateObject("Word.Application")
WORD.Visible = True
Set DOC = WORD.Documents.Open("C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx")
With DOC
.Application.Selection.Find.Text = "#FORO"
.Application.Selection.Find.Execute
.Application.Selection.Range = FORO
.Application.Selection.Find.Text = "#COMARCA"
.Application.Selection.Find.Execute
.Application.Selection.Range = COMARCA
.Application.Selection.Find.Text = "#UF"
.Application.Selection.Find.Execute
.Application.Selection.Range = UCase(UF)
.Application.Selection.Find.Text = "#PROCESSO_NUMERO"
.Application.Selection.Find.Execute
.Application.Selection.Range = PROCESSO_NUMERO
.Application.Selection.Find.Text = "#POLO_ATIVO"
.Application.Selection.Find.Execute
.Application.Selection.Range = POLO_ATIVO
.Application.Selection.Find.Text = "#COBRANCA_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = COBRANCA_VALOR
.Application.Selection.Find.Text = "#CONTRATO"
.Application.Selection.Find.Execute
.Application.Selection.Range = CONTRATO
If Me.RESUMO_DEFESA Like "*Prescrição*" Then
.Application.Selection.Find.Text = "#NEGATIVACAO_DATA"
.Application.Selection.Find.Execute
.Application.Selection.Range = NEGATIVACAO_DATA
.Application.Selection.Find.Text = "#DISTRIBUICAO_DATA"
.Application.Selection.Find.Execute
.Application.Selection.Range = DISTRIBUICAO_DATA
'.Application.Selection.Find.Text = "#DATA_NEGATIVACAO"
' .Application.Selection.Find.Execute
'.Application.Selection.Range = NEGATIVACAO_DATA
' .Application.Selection.Find.Text = "#PRESCRICAO_DATA"
' .Application.Selection.Find.Execute
'.Application.Selection.Range = PRESCRICAO_DATA
'.Application.Selection.Range = DateAdd("aaaa", 3, NEGATIVACAO_DATA)
'.Application.Selection.Find.Text = "#DATA_DISTRIBUICAO"
'.Application.Selection.Find.Execute
' .Application.Selection.Range = DISTRIBUICAO_DATA
End If
.Application.Selection.Find.Text = "#RESIDENCIA"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\residencia.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#SERASA"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\serasa.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#LINHA"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA
.Application.Selection.Find.Text = "#CONTRATO"
.Application.Selection.Find.Execute
.Application.Selection.Range = CONTRATO
.Application.Selection.Find.Text = "#LINHA_CONTRATACAO"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA_CONTRATACAO
.Application.Selection.Find.Text = "#LINHA_CANCELAMENTO"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA_CANCELAMENTO
'.Application.Selection.Find.Text = "#LINHA_CONTRATACAO"
' .Application.Selection.Find.Execute
'.Application.Selection.Range = LINHA_CONTRATACAO
' .Application.Selection.Find.Text = "#PAGAMENTO_1"
' .Application.Selection.Find.Execute
'.Application.Selection.Range = PAGAMENTO_1
' .Application.Selection.Find.Text = "#PAGAMENTO_ULTIMO"
' .Application.Selection.Find.Execute
' .Application.Selection.Range = PAGAMENTO_ULTIMO
'.Application.Selection.Find.Text = "#LINHA_CANCELAMENTO"
' .Application.Selection.Find.Execute
' .Application.Selection.Range = LINHA_CANCELAMENTO
' .Application.Selection.Find.Text = "#NEGATIVACAO_DATA"
' .Application.Selection.Find.Execute
' .Application.Selection.Range = NEGATIVACAO_DATA
.Application.Selection.Find.Text = "#TELA DE CADASTRO"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de cadastro.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#TELA DE ACESSO"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de acesso.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#TELA DE ENDEREÇO"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de endereco.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#TELA DE PAGAMENTOS"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de pagamentos.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#TELA DE DEBITOS"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de debitos.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#DEBITO_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = DEBITO_VALOR
.Application.Selection.Find.Text = "#DEBITO_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = DEBITO_VALOR
.Save
If MsgBox("Deseja fechar a defesa", vbYesNo) = vbYes Then
.Close
End If
'strLocal = "C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" & Me.POLO_ATIVO & " - " & Me.PROCESSO_NUMERO & " - " & Me.ESTADO & "\" & "Vincular\" & Me.POLO_ATIVO & ".docx"
'strLocal = strLocal & "-" & Format(Now, "hhmmss") & ".docx"
'.ActiveDocument.SaveAs strLocal
'.ActiveDocument.Close
'.ActiveDocument.SaveAs "C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx"
'.ActiveDocument.SaveAs "C:\" & "LDB_PF " & Replace(Me.POLO_ATIVO, "/", "-") & ".docX"
'.Close
End With
'WORD.Quit
Set DOC = Nothing
Set WORD = Nothing
TrataErro:
'Se um campo do formulário estiver vazio, remove o texto do Indicador e continua
If Err.Number = 94 Or Err.Number = 424 Or Err.Number = 5152 Then
WORD.Application.Selection.Range = ""
Resume Next
End If
End Function
Public Function Fncmesclarscore()
On Error GoTo TrataErro
Dim strLocal As String
Dim WORD As WORD.Application
Dim DOC As WORD.Document
Set WORD = CreateObject("Word.Application")
WORD.Visible = True
Set DOC = WORD.Documents.Open("C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx")
'Set DOC = WORD.Documents.Open("D:\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx")
With DOC
.Application.Selection.Find.Text = "#FORO"
.Application.Selection.Find.Execute
.Application.Selection.Range = FORO
.Application.Selection.Find.Text = "#COMARCA"
.Application.Selection.Find.Execute
.Application.Selection.Range = COMARCA
.Application.Selection.Find.Text = "#UF"
.Application.Selection.Find.Execute
.Application.Selection.Range = UCase(UF)
.Application.Selection.Find.Text = "#PROCESSO_NUMERO"
.Application.Selection.Find.Execute
.Application.Selection.Range = PROCESSO_NUMERO
.Application.Selection.Find.Text = "#POLO_ATIVO"
.Application.Selection.Find.Execute
.Application.Selection.Range = POLO_ATIVO
.Application.Selection.Find.Text = "#COBRANCA_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = COBRANCA_VALOR
.Application.Selection.Find.Text = "#CONTRATO"
.Application.Selection.Find.Execute
.Application.Selection.Range = CONTRATO
.Application.Selection.Find.Text = "#NEGATIVACAO_DATA"
.Application.Selection.Find.Execute
.Application.Selection.Range = NEGATIVACAO_DATA
.Application.Selection.Find.Text = "#DISTRIBUICAO_DATA"
.Application.Selection.Find.Execute
.Application.Selection.Range = DISTRIBUICAO_DATA
.Application.Selection.Find.Text = "#RESIDENCIA"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\residencia.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#SERASA"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\serasa.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#LINHA"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA
.Application.Selection.Find.Text = "#CONTRATO"
.Application.Selection.Find.Execute
.Application.Selection.Range = CONTRATO
.Application.Selection.Find.Text = "#LINHA_CONTRATACAO"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA_CONTRATACAO
.Application.Selection.Find.Text = "#LINHA_CANCELAMENTO"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA_CANCELAMENTO
.Application.Selection.Find.Text = "#DEBITO_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = DEBITO_VALOR
.Application.Selection.Find.Text = "#DEBITO_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = DEBITO_VALOR
.Save
.Close
'strLocal = "C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" & Me.POLO_ATIVO & " - " & Me.PROCESSO_NUMERO & " - " & Me.ESTADO & "\" & "Vincular\" & Me.POLO_ATIVO & ".docx"
'strLocal = strLocal & "-" & Format(Now, "hhmmss") & ".docx"
'.ActiveDocument.SaveAs strLocal
'.ActiveDocument.Close
'.ActiveDocument.SaveAs "C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx"
'.ActiveDocument.SaveAs "C:\" & "LDB_PF " & Replace(Me.POLO_ATIVO, "/", "-") & ".docX"
'.Close
End With
'WORD.Quit
Set DOC = Nothing
Set WORD = Nothing
TrataErro:
'Se um campo do formulário estiver vazio, remove o texto do Indicador e continua
If Err.Number = 94 Or Err.Number = 424 Or Err.Number = 5152 Then
WORD.Application.Selection.Range = ""
Resume Next
End If
End Function
Eu tenho o código abaixo que utilizo no access para preencher um arquivo word através de informações do banco de dados, tudo estava funcionando perfeitamente até incluírem no modelo campos que estão dentro de caixas de textos. Ocorre que agora não consigo localizar as informações que estão dentro de caixas de textos para substituir.
Segue código abaixo, a parte que está como comentário é justamente a parte em que os campos estão dentro de caixas de textos.
Public Function Fncmesclar()
On Error GoTo TrataErro
Dim strLocal As String
Dim WORD As WORD.Application
Dim DOC As WORD.Document
Set WORD = CreateObject("Word.Application")
WORD.Visible = True
Set DOC = WORD.Documents.Open("C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx")
With DOC
.Application.Selection.Find.Text = "#FORO"
.Application.Selection.Find.Execute
.Application.Selection.Range = FORO
.Application.Selection.Find.Text = "#COMARCA"
.Application.Selection.Find.Execute
.Application.Selection.Range = COMARCA
.Application.Selection.Find.Text = "#UF"
.Application.Selection.Find.Execute
.Application.Selection.Range = UCase(UF)
.Application.Selection.Find.Text = "#PROCESSO_NUMERO"
.Application.Selection.Find.Execute
.Application.Selection.Range = PROCESSO_NUMERO
.Application.Selection.Find.Text = "#POLO_ATIVO"
.Application.Selection.Find.Execute
.Application.Selection.Range = POLO_ATIVO
.Application.Selection.Find.Text = "#COBRANCA_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = COBRANCA_VALOR
.Application.Selection.Find.Text = "#CONTRATO"
.Application.Selection.Find.Execute
.Application.Selection.Range = CONTRATO
If Me.RESUMO_DEFESA Like "*Prescrição*" Then
.Application.Selection.Find.Text = "#NEGATIVACAO_DATA"
.Application.Selection.Find.Execute
.Application.Selection.Range = NEGATIVACAO_DATA
.Application.Selection.Find.Text = "#DISTRIBUICAO_DATA"
.Application.Selection.Find.Execute
.Application.Selection.Range = DISTRIBUICAO_DATA
'.Application.Selection.Find.Text = "#DATA_NEGATIVACAO"
' .Application.Selection.Find.Execute
'.Application.Selection.Range = NEGATIVACAO_DATA
' .Application.Selection.Find.Text = "#PRESCRICAO_DATA"
' .Application.Selection.Find.Execute
'.Application.Selection.Range = PRESCRICAO_DATA
'.Application.Selection.Range = DateAdd("aaaa", 3, NEGATIVACAO_DATA)
'.Application.Selection.Find.Text = "#DATA_DISTRIBUICAO"
'.Application.Selection.Find.Execute
' .Application.Selection.Range = DISTRIBUICAO_DATA
End If
.Application.Selection.Find.Text = "#RESIDENCIA"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\residencia.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#SERASA"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\serasa.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#LINHA"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA
.Application.Selection.Find.Text = "#CONTRATO"
.Application.Selection.Find.Execute
.Application.Selection.Range = CONTRATO
.Application.Selection.Find.Text = "#LINHA_CONTRATACAO"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA_CONTRATACAO
.Application.Selection.Find.Text = "#LINHA_CANCELAMENTO"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA_CANCELAMENTO
'.Application.Selection.Find.Text = "#LINHA_CONTRATACAO"
' .Application.Selection.Find.Execute
'.Application.Selection.Range = LINHA_CONTRATACAO
' .Application.Selection.Find.Text = "#PAGAMENTO_1"
' .Application.Selection.Find.Execute
'.Application.Selection.Range = PAGAMENTO_1
' .Application.Selection.Find.Text = "#PAGAMENTO_ULTIMO"
' .Application.Selection.Find.Execute
' .Application.Selection.Range = PAGAMENTO_ULTIMO
'.Application.Selection.Find.Text = "#LINHA_CANCELAMENTO"
' .Application.Selection.Find.Execute
' .Application.Selection.Range = LINHA_CANCELAMENTO
' .Application.Selection.Find.Text = "#NEGATIVACAO_DATA"
' .Application.Selection.Find.Execute
' .Application.Selection.Range = NEGATIVACAO_DATA
.Application.Selection.Find.Text = "#TELA DE CADASTRO"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de cadastro.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#TELA DE ACESSO"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de acesso.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#TELA DE ENDEREÇO"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de endereco.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#TELA DE PAGAMENTOS"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de pagamentos.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#TELA DE DEBITOS"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\tela de debitos.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#DEBITO_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = DEBITO_VALOR
.Application.Selection.Find.Text = "#DEBITO_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = DEBITO_VALOR
.Save
If MsgBox("Deseja fechar a defesa", vbYesNo) = vbYes Then
.Close
End If
'strLocal = "C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" & Me.POLO_ATIVO & " - " & Me.PROCESSO_NUMERO & " - " & Me.ESTADO & "\" & "Vincular\" & Me.POLO_ATIVO & ".docx"
'strLocal = strLocal & "-" & Format(Now, "hhmmss") & ".docx"
'.ActiveDocument.SaveAs strLocal
'.ActiveDocument.Close
'.ActiveDocument.SaveAs "C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx"
'.ActiveDocument.SaveAs "C:\" & "LDB_PF " & Replace(Me.POLO_ATIVO, "/", "-") & ".docX"
'.Close
End With
'WORD.Quit
Set DOC = Nothing
Set WORD = Nothing
TrataErro:
'Se um campo do formulário estiver vazio, remove o texto do Indicador e continua
If Err.Number = 94 Or Err.Number = 424 Or Err.Number = 5152 Then
WORD.Application.Selection.Range = ""
Resume Next
End If
End Function
Public Function Fncmesclarscore()
On Error GoTo TrataErro
Dim strLocal As String
Dim WORD As WORD.Application
Dim DOC As WORD.Document
Set WORD = CreateObject("Word.Application")
WORD.Visible = True
Set DOC = WORD.Documents.Open("C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx")
'Set DOC = WORD.Documents.Open("D:\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx")
With DOC
.Application.Selection.Find.Text = "#FORO"
.Application.Selection.Find.Execute
.Application.Selection.Range = FORO
.Application.Selection.Find.Text = "#COMARCA"
.Application.Selection.Find.Execute
.Application.Selection.Range = COMARCA
.Application.Selection.Find.Text = "#UF"
.Application.Selection.Find.Execute
.Application.Selection.Range = UCase(UF)
.Application.Selection.Find.Text = "#PROCESSO_NUMERO"
.Application.Selection.Find.Execute
.Application.Selection.Range = PROCESSO_NUMERO
.Application.Selection.Find.Text = "#POLO_ATIVO"
.Application.Selection.Find.Execute
.Application.Selection.Range = POLO_ATIVO
.Application.Selection.Find.Text = "#COBRANCA_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = COBRANCA_VALOR
.Application.Selection.Find.Text = "#CONTRATO"
.Application.Selection.Find.Execute
.Application.Selection.Range = CONTRATO
.Application.Selection.Find.Text = "#NEGATIVACAO_DATA"
.Application.Selection.Find.Execute
.Application.Selection.Range = NEGATIVACAO_DATA
.Application.Selection.Find.Text = "#DISTRIBUICAO_DATA"
.Application.Selection.Find.Execute
.Application.Selection.Range = DISTRIBUICAO_DATA
.Application.Selection.Find.Text = "#RESIDENCIA"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\residencia.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#SERASA"
.Application.Selection.Find.Execute
.Application.Selection.InlineShapes.AddPicture FileName:="C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\serasa.jpg", LinkToFile:=False, SaveWithDocument:=True
.Application.Selection.Find.Text = "#LINHA"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA
.Application.Selection.Find.Text = "#CONTRATO"
.Application.Selection.Find.Execute
.Application.Selection.Range = CONTRATO
.Application.Selection.Find.Text = "#LINHA_CONTRATACAO"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA_CONTRATACAO
.Application.Selection.Find.Text = "#LINHA_CANCELAMENTO"
.Application.Selection.Find.Execute
.Application.Selection.Range = LINHA_CANCELAMENTO
.Application.Selection.Find.Text = "#DEBITO_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = DEBITO_VALOR
.Application.Selection.Find.Text = "#DEBITO_VALOR"
.Application.Selection.Find.Execute
.Application.Selection.Range = DEBITO_VALOR
.Save
.Close
'strLocal = "C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" & Me.POLO_ATIVO & " - " & Me.PROCESSO_NUMERO & " - " & Me.ESTADO & "\" & "Vincular\" & Me.POLO_ATIVO & ".docx"
'strLocal = strLocal & "-" & Format(Now, "hhmmss") & ".docx"
'.ActiveDocument.SaveAs strLocal
'.ActiveDocument.Close
'.ActiveDocument.SaveAs "C:\Users\Patrick\OneDrive\CMartins\Patrick\Defesas\" + Me.POLO_ATIVO + " - " + Me.PROCESSO_NUMERO + " - " + Me.ESTADO + "\" + "Vincular\" + "CONTESTAÇÃO" + "-" + Me.POLO_ATIVO + "-" + "ADV " + Me.ADVOGADO_AUTOR_NOME + "-" + Me.UF + ".docx"
'.ActiveDocument.SaveAs "C:\" & "LDB_PF " & Replace(Me.POLO_ATIVO, "/", "-") & ".docX"
'.Close
End With
'WORD.Quit
Set DOC = Nothing
Set WORD = Nothing
TrataErro:
'Se um campo do formulário estiver vazio, remove o texto do Indicador e continua
If Err.Number = 94 Or Err.Number = 424 Or Err.Number = 5152 Then
WORD.Application.Selection.Range = ""
Resume Next
End If
End Function