Forum Discussion
Smokemover
Jul 05, 2019Copper Contributor
Macro help. Importing Table into Word
Hello Everyone, I have recently started using macros in excel as I wanted to streamline some of my business. I have created a word template that is a generic proposal document for my business. I ...
Berndvbatanker
Jul 05, 2019Iron Contributor
Hi,
try this.
Sub ExcelZelleInWordDokument()
Dim wsApp As Object
Dim myDoc As Object
Dim myRange As Object
Dim myTab As Object
Dim Vardat As Variant
Dim intZeile As Integer
Dim intSpalte As Integer
Set wdApp = CreateObject("Word.application")
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add
Vardat = Tabelle1.Range("A1:D10").Value
Set myRange = myDoc.Range(0, 0)
Set myTab = myDoc.Tables.Add _
(Range:=myRange, _
NumRows:=UBound(Vardat, 1), _
NumColumns:=UBound(Vardat, 2))
For intZeile = 1 To UBound(Vardat, 1)
For intSpalte = 1 To UBound(Vardat, 2)
myTab.Cell(intZeile, intSpalte).Range.Text = Vardat(intZeile, intSpalte)
Next intSpalte
Next intZeile
End Sub
Best regards
Bernd
https://vba-tanker.com/