sylvietoin
Gebruiker
- Lid geworden
- 5 feb 2007
- Berichten
- 56
foutje , had niet gezien dat er een tweede blad stond aangegeven.
Dus zie oproep op blad 2
Dus zie oproep op blad 2
Laatst bewerkt:
Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
Sub Verzendadvies()
'Toin Scheepers created this routine dd 20-12-2008.
'
'This routine will export a range to a Word document
'It opens Word, paste the Excel range, stores the Word document and closes the Word application
Dim oWordApp As Object
Dim oWordDoc As Object
Dim oWSH As Object
Dim rExport As Range
Dim sFileName As String, sPath As String
Dim i As Long, i2 As Long
Set rExport = Worksheets("verzendadvies").Range("c9:j62") '<- Change as needed
'Find the path to "C:/8606/VERZENDADVIEZEN"
Set oWSH = CreateObject("WScript.Shell")
sPath = "c:\" & Worksheets("verzendadvies").Range("d29") & "\" & "verzendadviezen\"
'Assemble a filename for the Word document
'In this case use the value that is in the first cell of the exported range and append date
sFileName = Range("d29") & "-" & "Verzendadvies"
'Optional: make sure you have a unique filename
i = 1
While FileExists(sPath & "\" & sFileName & ".doc")
i2 = InStr(1, sFileName & ".doc", "(", vbTextCompare)
If i2 = 0 Then
sFileName = sFileName & "(" & i & ")"
Else
sFileName = Left(sFileName & "verzendadvies.doc", i2) & i & ")"
End If
i = i + 1
Wend
'Create a Word document.
Set oWordApp = CreateObject("Word.Application")
'Make the newly created Word instance visible
oWordApp.Visible = True
'Create a new document
Set oWordDoc = oWordApp.documents.Add
'Copy data
rExport.Copy
'Paste Excel range in Word (will be pasted in a table)
oWordApp.Selection.PasteSpecial Link:=False, Placement:=wdInLine
'Save the Word document
oWordDoc.SaveAs sPath & sFileName, wdFormatDocument
Sub opslag()
With GetObject(, "Word.Application").Application.documents.Add("C:\test-1.dot")
.SaveAs "C:\" & Worksheets("verzendadvies").Range("d29") & "\" & "verzendadviezen\" & Worksheets("verzendadvies").Range("d29") & "-" & "Verzendadvies.doc"
.StoryRanges(7).Fields.Update
.Close -1
End With
End Sub
'Insert Koptekst
.With.StoryRanges(7).Fields.Update
.Close -1
End With
'Close Word Application
oWordApp.Quit SaveChanges:=False
End Sub
'FileExists Function -> geeft TRUE terug als de file bestaat
Function FileExists(fname As String) As Boolean
FileExists = Dir(fname, vbNormal) > Empty
End Function
Je hebt overigens nog niet begrepen dat in het wordsjabloon een veld in de koptekst staat, dat automatisch de naam van het bestand weergeeft. Al jouw pogingen om iets met een koptekst te doen zijn daarom overbodig.
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.