Ik heb in VBA ingesteld dat er een word document aangemaakt word. Maar nu weergeeft hij alles met een regelafstand dubbel. Hoe kan ik in VBA instellen dat de regelafstand enkel moet zijn? Tevens de vraag hoe je een tabel kan invoegen via VBA in WORD
Code:
Sub CreateNewWordDoc()
' to test this code, paste it into an Excel module
' add a reference to the Word-library
' create a new folder named C:\Foldername or edit the filnames in the code
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
relatie = Sheets("Startscherm").Range("G21").value
Dim lookFor As Range
Dim rng As Range
Dim col As Integer
Dim found As Integer
Dim value As Integer
Set value2 = Sheets("Startscherm").Range("B25")
Set lookFor = Sheets("Startscherm").Range("G21")
Set rng = Sheets("Relaties").Columns("A:C")
On Error Resume Next
relatie2 = Application.VLookup(lookFor.value, rng, 2, 0)
relatie3 = Application.VLookup(lookFor.value, rng, 3, 0)
On Error GoTo 0
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add ' create a new document
' or
'Set wrdDoc = wrdApp.Documents.Open("C:\Foldername\Filename.doc")
' open an existing document
' example word operations
With wrdDoc
.Content.InsertAfter relatie
.Content.InsertParagraphAfter
.Content.InsertAfter relatie2
.Content.InsertParagraphAfter
.Content.InsertAfter relatie3
.Content.InsertParagraphAfter
.Content.InsertAfter ("Beverwijk, " & Format(Date, "dd mmmm yyyy"))
.Content.InsertParagraphAfter
.Content.InsertAfter "Factuurnummer"
.Content.InsertParagraphAfter
.Content.InsertAfter "Betreft"
.Content.InsertParagraphAfter
.Content.InsertAfter "Werkzaamheden in november, 2010 volgens bijgevoegde specificatie"
.Content.InsertParagraphAfter
.Content.InsertAfter "Totaal €"
.Content.InsertParagraphAfter
.Content.InsertAfter "B.T.W. 19% €"
.Content.InsertParagraphAfter
.Content.InsertAfter "Totaal €"
.Content.InsertParagraphAfter
.Content.InsertParagraphAfter
End With
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub