• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

VBA styles("no spacing") plaatsen

Status
Niet open voor verdere reacties.

gl3nn1987

Gebruiker
Lid geworden
24 sep 2010
Berichten
120
Ik wil een nieuw Word document aanmaken met de tekst vanuit excel, nu lukt dit goed alleen staat de regelafstand automatisch op standaard. Hoe krijg ik de regelafstand gewoon op 0 vanuit de macro. Ik las iets over styles("no spacing") maar ik krijg hem maar niet werkend. Iemand die me kan helpen?

Hieronder mijn stuk

Code:
Sub CreateNewWordDoc()


    Dim c      As Range
    y = 1
    
    With Sheets("Factuur")
    With .[A3].CurrentRegion
            .ClearContents
            .Font.FontStyle = "Standaard"
        End With
        With .[A1].Resize(, 6)
            .value = Split("Datum|Omschrijving werkzaamheden|Uren|Tarief|Bedrag|Werknemer", "|")
            .Font.FontStyle = "Bold"
            .Interior.ColorIndex = 44
            .Borders.LineStyle = xlContinuous
        End With

        For Each c In Sheets("Agenda").Range("A2:A" & Sheets("Agenda").Cells(Rows.Count, 1).End(xlUp).Row)
            If c >= [Startscherm!G17] And c <= [Startscherm!G19] And c.Offset(, 1) = [Startscherm!G21] Then
                .Range("A" & y).Offset(1, 0).Resize(, 5) = Sheets("Agenda").Cells(c.Row, 1).Resize(, 5).value
                .Range("A" & y).Offset(1, 5).Resize(, 1) = Sheets("Agenda").Cells(c.Row, 8).Resize(, 1).value
                y = y + 1
            End If
        Next
    With .Range("A2:F65536")
    .Interior.ColorIndex = 0
            .Borders.LineStyle = xlContinuous
            End With
    With .Range("B65536").End(xlUp)
        .Offset(1) = "Totaal"
        .Offset(1).Resize(, 4).Font.FontStyle = "Bold"
    End With
totaal = WorksheetFunction.Sum(.Range("E2:E" & .Cells(Rows.Count, 5).End(xlUp).Row))
btw = totaal * 0.19
totaalb = totaal + btw
    .Range("C65536").End(xlUp).Offset(1) = WorksheetFunction.Sum(.Range("C2:C" & .Cells(Rows.Count, 5).End(xlUp).Row))
    .Range("E65536").End(xlUp).Offset(1) = totaal
    End With
' 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 & vbCrLf & 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 € " & totaal
.Content.InsertParagraphAfter
    .Content.InsertAfter "B.T.W. 19%  € " & btw
.Content.InsertParagraphAfter
    .Content.InsertAfter "Totaal € " & totaalb
.Content.InsertParagraphAfter
    .Content.InsertAfter "U wordt verzocht het totaalbedrag binnen 14 dagen over te maken op onderstaand rekeningnummer bij de Rabobank, onder vermelding van het factuurnummer"
        
    End With
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
End Sub
 
Stel deze vraag ook eens in het Word-forum met een link naar deze vraag en omgekeerd.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan