Ik heb de onderstaande tekst gevonden op internet om een word document aan te maken vanuit VGA. Ik heb dit nodig omdat ik bezig ben met een factuur programma. Nu snap ik niet hoe ik de 2e regel moet doen. "add a reference to the Word-library". Iemand die me kan helpen hierbij, of een beter alternatief heeft? Uiteindelijk heb ik een vast stuk tekst waarbij de bedragen telkens verschillen. Ik wil niet met koppelingen werken die je meot bijwerken, echt puur uit excell.
[SQL]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
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
For i = 1 To 100
.Content.InsertAfter "Here is a example test line #" & i
.Content.InsertParagraphAfter
Next i
If Dir("C:\Users\Glenn\Documents\MyNewWordDoc.doc") <> "" Then
Kill "C:\Users\Glenn\Documents\MyNewWordDoc.doc"
End If
.SaveAs ("C:\Users\Glenn\Documents\MyNewWordDoc.doc")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
[/SQL]
[SQL]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
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
For i = 1 To 100
.Content.InsertAfter "Here is a example test line #" & i
.Content.InsertParagraphAfter
Next i
If Dir("C:\Users\Glenn\Documents\MyNewWordDoc.doc") <> "" Then
Kill "C:\Users\Glenn\Documents\MyNewWordDoc.doc"
End If
.SaveAs ("C:\Users\Glenn\Documents\MyNewWordDoc.doc")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
[/SQL]