mqdias
01-17-2013, 04:36 AM
Hi,
I have the following code written in Excel VBA that creates a new word doc with some text.
Sub GerarTexto()
Dim Cell As Excel.Range
Dim Rng As Excel.Range
Dim RngEnd As Excel.Range
Dim wdApp As Object
Dim wdDoc As Object
Set Rng = Range("C10")
Set RngEnd = Cells(Rows.Count, "C").End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Range(Rng, RngEnd)
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add
With wdDoc
.Content.InsertAfter "Caro(a) " & ActiveSheet.Range("g6") & ". " & ActiveSheet.Range("i6")
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
.Content.InsertAfter "Com vista à elaboração do Relatório de Execução e Progresso, relativo ao ano de " & Folha1.Range("w4") & ", para avaliação do estado de implementação do ARCE, solicitamos o envio dos seguintes dados:" '& i
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
End With
For Each Cell In Rng
If Cell.Value = "x" Then
With wdDoc
.Content.InsertAfter " - "
.Content.InsertAfter Cell.Offset(0, 2) & vbCrLf
End With
End If
Next Cell
With wdDoc
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
.Content.InsertAfter "Ficamos a aguardar notícias da V/ parte com a brevidade possível." '& i
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
'.Content.Selection.WholeStory
'.Content.Selection.Font.Size = 11
'.Content.Selection.Font.Color = wdColorGray50
End With
wdApp.Visible = True
End Sub
At the end, you can see my attempt to write a code to select all text ant format it, but it doesn't work. Can anyone help me?
Thanks
I have the following code written in Excel VBA that creates a new word doc with some text.
Sub GerarTexto()
Dim Cell As Excel.Range
Dim Rng As Excel.Range
Dim RngEnd As Excel.Range
Dim wdApp As Object
Dim wdDoc As Object
Set Rng = Range("C10")
Set RngEnd = Cells(Rows.Count, "C").End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Range(Rng, RngEnd)
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add
With wdDoc
.Content.InsertAfter "Caro(a) " & ActiveSheet.Range("g6") & ". " & ActiveSheet.Range("i6")
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
.Content.InsertAfter "Com vista à elaboração do Relatório de Execução e Progresso, relativo ao ano de " & Folha1.Range("w4") & ", para avaliação do estado de implementação do ARCE, solicitamos o envio dos seguintes dados:" '& i
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
End With
For Each Cell In Rng
If Cell.Value = "x" Then
With wdDoc
.Content.InsertAfter " - "
.Content.InsertAfter Cell.Offset(0, 2) & vbCrLf
End With
End If
Next Cell
With wdDoc
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
.Content.InsertAfter "Ficamos a aguardar notícias da V/ parte com a brevidade possível." '& i
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
'.Content.Selection.WholeStory
'.Content.Selection.Font.Size = 11
'.Content.Selection.Font.Color = wdColorGray50
End With
wdApp.Visible = True
End Sub
At the end, you can see my attempt to write a code to select all text ant format it, but it doesn't work. Can anyone help me?
Thanks