Tenho este código abaixo mas o CPF e outros campos que exigem formatação própria, não aparecem com a formatação do Access:
Por exemplo, o CPF aparece assim no Word: 12345678900 e não aparece os pontos e o traço.
Private Sub VisualizarContrato_Click()
Dim AppWord As Object, strFinalDoc As String
strFinalDoc = CurrentProject.Path & "\ContratoModelo.rtf"
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True
Set DocWord = AppWord.Documents.Add(strFinalDoc)
With DocWord.Content.Find
.Execute findtext:="{DATA}", replacewith:=Data, Format:=True, Replace:=2
.Execute findtext:="{NRCONTRATO}", replacewith:=Me.NrContrato, Format:=True, Replace:=2
.Execute findtext:="{EMPREENDIMENTO}", replacewith:=Me.Empreendimento, Format:=True, Replace:=2
.Execute findtext:="{VENDEDORA}", replacewith:=Nz(Me.Vend1), Format:=True, Replace:=2
.Execute findtext:="{CNPJ}", replacewith:=Nz(Me.Vend1CNPJ), Format:=True, Replace:=2
.Execute findtext:="{ENDEREÇO}", replacewith:=Nz(Me.Vend1End), Format:=True, Replace:=2
.Execute findtext:="{CIDADE}", replacewith:=Nz(Me.Vend1Cidade), Format:=True, Replace:=2
.Execute findtext:="{ESTADO}", replacewith:=Nz(Me.Vend1Estado), Format:=True, Replace:=2
.Execute findtext:="{VENDEDORA2}", replacewith:=Nz(Me.Vend2), Format:=True, Replace:=2
.Execute findtext:="{CNPJVEND2}", replacewith:=Nz(Me.Vend2CNPJ), Format:=True, Replace:=2
.Execute findtext:="{ENDVEND2}", replacewith:=Nz(Me.Vend2End), Format:=True, Replace:=2
.Execute findtext:="{CIDADEVEND2}", replacewith:=Nz(Me.Vend2Cidade), Format:=True, Replace:=2
.Execute findtext:="{ESTADOVEND2}", replacewith:=Nz(Me.Vend2Estado), Format:=True, Replace:=2
.Execute findtext:="{TITULAR1}", replacewith:=Nz(Me.Vend1TitNome), Format:=True, Replace:=2
.Execute findtext:="{CPF1}", replacewith:=Nz(Me.Vend1TitCPF), Format:=True, Replace:=2
.Execute findtext:="{IDENTIDADE1}", replacewith:=Nz(Me.Vend1TitIdentidade), Format:=True, Replace:=2
.Execute findtext:="{ORGAOESTADO1}", replacewith:=Nz(Me.Vend1TitOrgaoEstado), Format:=True, Replace:=2
.Execute findtext:="{ENDEREÇO1}", replacewith:=Nz(Me.Vend1TitEndereço), Format:=True, Replace:=2
.Execute findtext:="{CIDADE1}", replacewith:=Nz(Me.Vend1TitCidade), Format:=True, Replace:=2
.Execute findtext:="{ESTADO1}", replacewith:=Nz(Me.Vend1TitEstado), Format:=True, Replace:=2
.Execute findtext:="{NAC1}", replacewith:=Nz(Me.Vend1TitNac), Format:=True, Replace:=2
.Execute findtext:="{ESTCIVIL1}", replacewith:=Nz(Me.Vend1TitEstCivil), Format:=True, Replace:=2
.Execute findtext:="{PROF1}", replacewith:=Nz(Me.Vend1TitProf), Format:=True, Replace:=2
.Execute findtext:="{TITULAR2}", replacewith:=Me.Vend2TitNome, Format:=True, Replace:=2
.Execute findtext:="{CPF2}", replacewith:=Me.Vend2TitCPF, Format:=True, Replace:=2
.Execute findtext:="{IDENTIDADE2}", replacewith:=Me.Vend2TitIdentidade, Format:=True, Replace:=2
.Execute findtext:="{ORGAOESTADO2}", replacewith:=Me.Vend2TitOrgaoEstado, Format:=True, Replace:=2
.Execute findtext:="{ENDEREÇO2}", replacewith:=Me.Vend2TitEndereço, Format:=True, Replace:=2
.Execute findtext:="{CIDADE2}", replacewith:=Me.Vend2TitCidade, Format:=True, Replace:=2
.Execute findtext:="{ESTADO2}", replacewith:=Me.Vend2TitEstado, Format:=True, Replace:=2
.Execute findtext:="{NAC2}", replacewith:=Me.Vend2TitNac, Format:=True, Replace:=2
.Execute findtext:="{ESTCIVIL2}", replacewith:=Me.Vend2TitEstCivil, Format:=True, Replace:=2
.Execute findtext:="{PROF2}", replacewith:=Me.Vend2TitProf, Format:=True, Replace:=2
.Execute findtext:="{NOMEC1}", replacewith:=Me.C1Nome, Format:=True, Replace:=2
.Execute findtext:="{NACC1}", replacewith:=Me.C1Nac, Format:=True, Replace:=2
.Execute findtext:="{ESTCIVILC1}", replacewith:=Me.C1EstCivil, Format:=True, Replace:=2
.Execute findtext:="{PROFC1}", replacewith:=Me.C1Prof, Format:=True, Replace:=2
.Execute findtext:="{IDENTC1}", replacewith:=Me.C1Ident, Format:=True, Replace:=2
.Execute findtext:="{ORGAOESTADOC1}", replacewith:=Me.C1OrgaoEstado, Format:=True, Replace:=2
.Execute findtext:="{CPFC1}", replacewith:=Me.C1Cpf, Format:=True, Replace:=2
.Execute findtext:="{ENDC1}", replacewith:=Me.C1End, Format:=True, Replace:=2
.Execute findtext:="{CIDADEC1}", replacewith:=Me.C1Cidade, Format:=True, Replace:=2
.Execute findtext:="{ESTADOC1}", replacewith:=Me.C1Estado, Format:=True, Replace:=2
.Execute findtext:="{CEPC1}", replacewith:=Me.C1Cep, Format:=True, Replace:=2
.Execute findtext:="{TELFIXOC1}", replacewith:=Nz(Me.C1Tel1), Format:=True, Replace:=2
.Execute findtext:="{TELCELC1}", replacewith:=Nz(Me.C1Tel2), Format:=True, Replace:=2
.Execute findtext:="{EMAILC1}", replacewith:=Nz(Me.C1Email), Format:=True, Replace:=2
.Execute findtext:="{NOMEC2}", replacewith:=Nz(Me.C2Nome), Format:=True, Replace:=2
.Execute findtext:="{NACC2}", replacewith:=Nz(Me.C2Nac), Format:=True, Replace:=2
.Execute findtext:="{ESTCIVILC2}", replacewith:=Nz(Me.C2EstCivil), Format:=True, Replace:=2
.Execute findtext:="{PROFC2}", replacewith:=Nz(Me.C2Prof), Format:=True, Replace:=2
.Execute findtext:="{IDENTC2}", replacewith:=Nz(Me.C2Ident), Format:=True, Replace:=2
.Execute findtext:="{ORGAOESTADOC2}", replacewith:=Nz(Me.C2OrgaoEstado), Format:=True, Replace:=2
.Execute findtext:="{CPFC2}", replacewith:=Nz(Me.C2Cpf), Format:=True, Replace:=2
.Execute findtext:="{ENDC2}", replacewith:=Nz(Me.C2End), Format:=True, Replace:=2
.Execute findtext:="{CIDADEC2}", replacewith:=Nz(Me.C2Cidade), Format:=True, Replace:=2
.Execute findtext:="{ESTADOC2}", replacewith:=Nz(Me.C2Estado), Format:=True, Replace:=2
.Execute findtext:="{CEPC2}", replacewith:=Nz(Me.C2Cep), Format:=True, Replace:=2
.Execute findtext:="{TELFIXOC2}", replacewith:=Nz(Me.C2Tel1), Format:=True, Replace:=2
.Execute findtext:="{TELCELC2}", replacewith:=Nz(Me.C2Tel2), Format:=True, Replace:=2
.Execute findtext:="{EMAILC2}", replacewith:=Nz(Me.C2Email), Format:=True, Replace:=2
.Execute findtext:="{LOTE}", replacewith:=Me.Lote, Format:=True, Replace:=2
.Execute findtext:="{QUADRA}", replacewith:=Me.Quadra, Format:=True, Replace:=2
.Execute findtext:="{LOGRADOURO}", replacewith:=Me.Logradouro, Format:=True, Replace:=2
.Execute findtext:="{FRENTE}", replacewith:=Me.Frente, Format:=True, Replace:=2
.Execute findtext:="{FUNDOS}", replacewith:=Me.Fundos, Format:=True, Replace:=2
.Execute findtext:="{LADODIREITO}", replacewith:=Me.LadoDireito, Format:=True, Replace:=2
.Execute findtext:="{LADOESQUERDO}", replacewith:=Me.LadoEsquerdo, Format:=True, Replace:=2
.Execute findtext:="{CHANFRO}", replacewith:=Nz(Me.Chanfro), Format:=True, Replace:=2
.Execute findtext:="{DIVFUNDOS}", replacewith:=Me.DivFundos, Format:=True, Replace:=2
.Execute findtext:="{DIVLD}", replacewith:=Me.DivLD, Format:=True, Replace:=2
.Execute findtext:="{DIVLE}", replacewith:=Me.DivLE, Format:=True, Replace:=2
.Execute findtext:="{METRAGEMTOTAL}", replacewith:=Me.MetragemTotal, Format:=True, Replace:=2
.Execute findtext:="{METRAGEMEXT}", replacewith:=Me.MetragemTotalExt, Format:=True, Replace:=2
.Execute findtext:="{VALORTOTAL}", replacewith:=Me.ValorTotal, Format:=True, Replace:=2
.Execute findtext:="{VALORTOTALEXT}", replacewith:=Me.ValorTotalExt, Format:=True, Replace:=2
.Execute findtext:="{QTDEPARCELA}", replacewith:=Me.QtdeParcelas, Format:=True, Replace:=2
.Execute findtext:="{QTDEPARCELAEXT}", replacewith:=Me.QtdeParcelasExt, Format:=True, Replace:=2
.Execute findtext:="{VALORPARCELA}", replacewith:=Me.ValorParcela, Format:=True, Replace:=2
.Execute findtext:="{VALORPARCELAEXT}", replacewith:=Me.ValorParcExt, Format:=True, Replace:=2
.Execute findtext:="{VENCPARCELA1}", replacewith:=Me.VencParcela1, Format:=True, Replace:=2
.Execute findtext:="{DATACORREÇÃO}", replacewith:=Me.DataCorreção, Format:=True, Replace:=2
EscribeWord (Me.Id)
DoEvents
If MsgBox("Visualizar Contrato " & vbCrLf & Me.NrContrato & "-" & Me.NomeC1, vbExclamation + vbNo, "Confirme") = vbYes Then
AppWord.PrintOut
End If
'DocWord.Open True
Set DocWord = Nothing
End With
AppWord.Quit
Set AppWord = Nothing
End Sub
----------------------------------------------------------------------------------------
Atenciosamente
Ari
Por exemplo, o CPF aparece assim no Word: 12345678900 e não aparece os pontos e o traço.
Private Sub VisualizarContrato_Click()
Dim AppWord As Object, strFinalDoc As String
strFinalDoc = CurrentProject.Path & "\ContratoModelo.rtf"
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True
Set DocWord = AppWord.Documents.Add(strFinalDoc)
With DocWord.Content.Find
.Execute findtext:="{DATA}", replacewith:=Data, Format:=True, Replace:=2
.Execute findtext:="{NRCONTRATO}", replacewith:=Me.NrContrato, Format:=True, Replace:=2
.Execute findtext:="{EMPREENDIMENTO}", replacewith:=Me.Empreendimento, Format:=True, Replace:=2
.Execute findtext:="{VENDEDORA}", replacewith:=Nz(Me.Vend1), Format:=True, Replace:=2
.Execute findtext:="{CNPJ}", replacewith:=Nz(Me.Vend1CNPJ), Format:=True, Replace:=2
.Execute findtext:="{ENDEREÇO}", replacewith:=Nz(Me.Vend1End), Format:=True, Replace:=2
.Execute findtext:="{CIDADE}", replacewith:=Nz(Me.Vend1Cidade), Format:=True, Replace:=2
.Execute findtext:="{ESTADO}", replacewith:=Nz(Me.Vend1Estado), Format:=True, Replace:=2
.Execute findtext:="{VENDEDORA2}", replacewith:=Nz(Me.Vend2), Format:=True, Replace:=2
.Execute findtext:="{CNPJVEND2}", replacewith:=Nz(Me.Vend2CNPJ), Format:=True, Replace:=2
.Execute findtext:="{ENDVEND2}", replacewith:=Nz(Me.Vend2End), Format:=True, Replace:=2
.Execute findtext:="{CIDADEVEND2}", replacewith:=Nz(Me.Vend2Cidade), Format:=True, Replace:=2
.Execute findtext:="{ESTADOVEND2}", replacewith:=Nz(Me.Vend2Estado), Format:=True, Replace:=2
.Execute findtext:="{TITULAR1}", replacewith:=Nz(Me.Vend1TitNome), Format:=True, Replace:=2
.Execute findtext:="{CPF1}", replacewith:=Nz(Me.Vend1TitCPF), Format:=True, Replace:=2
.Execute findtext:="{IDENTIDADE1}", replacewith:=Nz(Me.Vend1TitIdentidade), Format:=True, Replace:=2
.Execute findtext:="{ORGAOESTADO1}", replacewith:=Nz(Me.Vend1TitOrgaoEstado), Format:=True, Replace:=2
.Execute findtext:="{ENDEREÇO1}", replacewith:=Nz(Me.Vend1TitEndereço), Format:=True, Replace:=2
.Execute findtext:="{CIDADE1}", replacewith:=Nz(Me.Vend1TitCidade), Format:=True, Replace:=2
.Execute findtext:="{ESTADO1}", replacewith:=Nz(Me.Vend1TitEstado), Format:=True, Replace:=2
.Execute findtext:="{NAC1}", replacewith:=Nz(Me.Vend1TitNac), Format:=True, Replace:=2
.Execute findtext:="{ESTCIVIL1}", replacewith:=Nz(Me.Vend1TitEstCivil), Format:=True, Replace:=2
.Execute findtext:="{PROF1}", replacewith:=Nz(Me.Vend1TitProf), Format:=True, Replace:=2
.Execute findtext:="{TITULAR2}", replacewith:=Me.Vend2TitNome, Format:=True, Replace:=2
.Execute findtext:="{CPF2}", replacewith:=Me.Vend2TitCPF, Format:=True, Replace:=2
.Execute findtext:="{IDENTIDADE2}", replacewith:=Me.Vend2TitIdentidade, Format:=True, Replace:=2
.Execute findtext:="{ORGAOESTADO2}", replacewith:=Me.Vend2TitOrgaoEstado, Format:=True, Replace:=2
.Execute findtext:="{ENDEREÇO2}", replacewith:=Me.Vend2TitEndereço, Format:=True, Replace:=2
.Execute findtext:="{CIDADE2}", replacewith:=Me.Vend2TitCidade, Format:=True, Replace:=2
.Execute findtext:="{ESTADO2}", replacewith:=Me.Vend2TitEstado, Format:=True, Replace:=2
.Execute findtext:="{NAC2}", replacewith:=Me.Vend2TitNac, Format:=True, Replace:=2
.Execute findtext:="{ESTCIVIL2}", replacewith:=Me.Vend2TitEstCivil, Format:=True, Replace:=2
.Execute findtext:="{PROF2}", replacewith:=Me.Vend2TitProf, Format:=True, Replace:=2
.Execute findtext:="{NOMEC1}", replacewith:=Me.C1Nome, Format:=True, Replace:=2
.Execute findtext:="{NACC1}", replacewith:=Me.C1Nac, Format:=True, Replace:=2
.Execute findtext:="{ESTCIVILC1}", replacewith:=Me.C1EstCivil, Format:=True, Replace:=2
.Execute findtext:="{PROFC1}", replacewith:=Me.C1Prof, Format:=True, Replace:=2
.Execute findtext:="{IDENTC1}", replacewith:=Me.C1Ident, Format:=True, Replace:=2
.Execute findtext:="{ORGAOESTADOC1}", replacewith:=Me.C1OrgaoEstado, Format:=True, Replace:=2
.Execute findtext:="{CPFC1}", replacewith:=Me.C1Cpf, Format:=True, Replace:=2
.Execute findtext:="{ENDC1}", replacewith:=Me.C1End, Format:=True, Replace:=2
.Execute findtext:="{CIDADEC1}", replacewith:=Me.C1Cidade, Format:=True, Replace:=2
.Execute findtext:="{ESTADOC1}", replacewith:=Me.C1Estado, Format:=True, Replace:=2
.Execute findtext:="{CEPC1}", replacewith:=Me.C1Cep, Format:=True, Replace:=2
.Execute findtext:="{TELFIXOC1}", replacewith:=Nz(Me.C1Tel1), Format:=True, Replace:=2
.Execute findtext:="{TELCELC1}", replacewith:=Nz(Me.C1Tel2), Format:=True, Replace:=2
.Execute findtext:="{EMAILC1}", replacewith:=Nz(Me.C1Email), Format:=True, Replace:=2
.Execute findtext:="{NOMEC2}", replacewith:=Nz(Me.C2Nome), Format:=True, Replace:=2
.Execute findtext:="{NACC2}", replacewith:=Nz(Me.C2Nac), Format:=True, Replace:=2
.Execute findtext:="{ESTCIVILC2}", replacewith:=Nz(Me.C2EstCivil), Format:=True, Replace:=2
.Execute findtext:="{PROFC2}", replacewith:=Nz(Me.C2Prof), Format:=True, Replace:=2
.Execute findtext:="{IDENTC2}", replacewith:=Nz(Me.C2Ident), Format:=True, Replace:=2
.Execute findtext:="{ORGAOESTADOC2}", replacewith:=Nz(Me.C2OrgaoEstado), Format:=True, Replace:=2
.Execute findtext:="{CPFC2}", replacewith:=Nz(Me.C2Cpf), Format:=True, Replace:=2
.Execute findtext:="{ENDC2}", replacewith:=Nz(Me.C2End), Format:=True, Replace:=2
.Execute findtext:="{CIDADEC2}", replacewith:=Nz(Me.C2Cidade), Format:=True, Replace:=2
.Execute findtext:="{ESTADOC2}", replacewith:=Nz(Me.C2Estado), Format:=True, Replace:=2
.Execute findtext:="{CEPC2}", replacewith:=Nz(Me.C2Cep), Format:=True, Replace:=2
.Execute findtext:="{TELFIXOC2}", replacewith:=Nz(Me.C2Tel1), Format:=True, Replace:=2
.Execute findtext:="{TELCELC2}", replacewith:=Nz(Me.C2Tel2), Format:=True, Replace:=2
.Execute findtext:="{EMAILC2}", replacewith:=Nz(Me.C2Email), Format:=True, Replace:=2
.Execute findtext:="{LOTE}", replacewith:=Me.Lote, Format:=True, Replace:=2
.Execute findtext:="{QUADRA}", replacewith:=Me.Quadra, Format:=True, Replace:=2
.Execute findtext:="{LOGRADOURO}", replacewith:=Me.Logradouro, Format:=True, Replace:=2
.Execute findtext:="{FRENTE}", replacewith:=Me.Frente, Format:=True, Replace:=2
.Execute findtext:="{FUNDOS}", replacewith:=Me.Fundos, Format:=True, Replace:=2
.Execute findtext:="{LADODIREITO}", replacewith:=Me.LadoDireito, Format:=True, Replace:=2
.Execute findtext:="{LADOESQUERDO}", replacewith:=Me.LadoEsquerdo, Format:=True, Replace:=2
.Execute findtext:="{CHANFRO}", replacewith:=Nz(Me.Chanfro), Format:=True, Replace:=2
.Execute findtext:="{DIVFUNDOS}", replacewith:=Me.DivFundos, Format:=True, Replace:=2
.Execute findtext:="{DIVLD}", replacewith:=Me.DivLD, Format:=True, Replace:=2
.Execute findtext:="{DIVLE}", replacewith:=Me.DivLE, Format:=True, Replace:=2
.Execute findtext:="{METRAGEMTOTAL}", replacewith:=Me.MetragemTotal, Format:=True, Replace:=2
.Execute findtext:="{METRAGEMEXT}", replacewith:=Me.MetragemTotalExt, Format:=True, Replace:=2
.Execute findtext:="{VALORTOTAL}", replacewith:=Me.ValorTotal, Format:=True, Replace:=2
.Execute findtext:="{VALORTOTALEXT}", replacewith:=Me.ValorTotalExt, Format:=True, Replace:=2
.Execute findtext:="{QTDEPARCELA}", replacewith:=Me.QtdeParcelas, Format:=True, Replace:=2
.Execute findtext:="{QTDEPARCELAEXT}", replacewith:=Me.QtdeParcelasExt, Format:=True, Replace:=2
.Execute findtext:="{VALORPARCELA}", replacewith:=Me.ValorParcela, Format:=True, Replace:=2
.Execute findtext:="{VALORPARCELAEXT}", replacewith:=Me.ValorParcExt, Format:=True, Replace:=2
.Execute findtext:="{VENCPARCELA1}", replacewith:=Me.VencParcela1, Format:=True, Replace:=2
.Execute findtext:="{DATACORREÇÃO}", replacewith:=Me.DataCorreção, Format:=True, Replace:=2
EscribeWord (Me.Id)
DoEvents
If MsgBox("Visualizar Contrato " & vbCrLf & Me.NrContrato & "-" & Me.NomeC1, vbExclamation + vbNo, "Confirme") = vbYes Then
AppWord.PrintOut
End If
'DocWord.Open True
Set DocWord = Nothing
End With
AppWord.Quit
Set AppWord = Nothing
End Sub
----------------------------------------------------------------------------------------
Atenciosamente
Ari