Danlps
31-12-2019 15:04:59
Olá pessoal,
Estou criação uma makro para exportar dados do excel para um documento word que já tem um layout definido.
Estou tentando enviar registros de linhas do excel para o word como heading style nível 3. Como posso realizar isso?
Estou tentando essa Makro mas está dando erro:
Function EscreverNoWord()
Dim objWord As New Word.Application 'o aplicativo Microsoft Word
Dim objDoc As New Excel.Application 'o documento do word em si (doc ou docx)
Dim Wordoc As Word.Document
Dim objSelection As Object
Dim myRange As Range
Dim text As String
Dim i As Long, k As Long
Worksheets("Prep.Doc").Select
Path = Range("D3")
File = Range("D4")
Set objWord = CreateObject("Word.Application")
Set Wordoc = objWord.Documents.Open(Filename:=Path & File)
objWord.Visible = True ' Word, mostre sua cara
If ActiveSheet.Index = Worksheets.Count Then
Worksheets(1).Select
Else
ActiveSheet.Next.Select
End If
Wordoc.ContentControls(1).Range.text = Range("I2")
Wordoc.ContentControls(2).Range.text = Range("I2")
Wordoc.ContentControls(3).Range.text = Range("L2")
Set objSelection = objDoc.ActiveWindow.Selection
With objSelection '<--| reference 'Selection' object
For i = 2 To 94
.TypeParagraph
.Style = objWord.ActiveDocument.Styles("Heading 3")
.TypeText text:=myRange(i, 2).text
Next
End With
End Function
Estou criação uma makro para exportar dados do excel para um documento word que já tem um layout definido.
Estou tentando enviar registros de linhas do excel para o word como heading style nível 3. Como posso realizar isso?
Estou tentando essa Makro mas está dando erro:
Function EscreverNoWord()
Dim objWord As New Word.Application 'o aplicativo Microsoft Word
Dim objDoc As New Excel.Application 'o documento do word em si (doc ou docx)
Dim Wordoc As Word.Document
Dim objSelection As Object
Dim myRange As Range
Dim text As String
Dim i As Long, k As Long
Worksheets("Prep.Doc").Select
Path = Range("D3")
File = Range("D4")
Set objWord = CreateObject("Word.Application")
Set Wordoc = objWord.Documents.Open(Filename:=Path & File)
objWord.Visible = True ' Word, mostre sua cara
If ActiveSheet.Index = Worksheets.Count Then
Worksheets(1).Select
Else
ActiveSheet.Next.Select
End If
Wordoc.ContentControls(1).Range.text = Range("I2")
Wordoc.ContentControls(2).Range.text = Range("I2")
Wordoc.ContentControls(3).Range.text = Range("L2")
Set objSelection = objDoc.ActiveWindow.Selection
With objSelection '<--| reference 'Selection' object
For i = 2 To 94
.TypeParagraph
.Style = objWord.ActiveDocument.Styles("Heading 3")
.TypeText text:=myRange(i, 2).text
Next
End With
End Function