Probleem opgelost
Thanks Edmoor leer weer steeds bij
mooie oplossing voor die kolom letter..
Cow18, morgen die van jouw proberen en snb
Nu even rust
Code:
Private Sub Uitvoering()
Dim Comtext As String, wordapp, WrdBestand As String, C As Comment, VarComment As String, selectedcell, Word, RijNummer As Integer
Dim cl As Range, i As Integer, pos1(10) As Integer, pos2(10) As Integer, veld(10) As String, aantal As Integer, KL As String
Worksheets("Blad1").Activate
Set selectedcell = Application.ActiveCell
KolomNummer = selectedcell.Column ' GEEFT KOLOM NUMMER https://www.educba.com/vba-active-cell/
KL = Kolom_Letter(KolomNummer) ' GEEFT KOLOMLETTER
RijNummer = selectedcell.Row ' GEEFT RIJNUMMER
If ActiveCell.Comment Is Nothing Then
Comtext = ""
MsgBox ("1 Er is geen comment"), vbExclamation
GoTo Uit
Else
Comtext = ActiveCell.Comment.Text
If Comtext = "" Then
MsgBox ("Er staat geen tekst in de Opmerking!")
GoTo Uit
End If
End If
WrdBestand = ActiveWorkbook.Worksheets("Blad1").Range("J10") & "\" & ActiveWorkbook.Worksheets("Blad1").Range("J12") & ".doc" ' opent BASIS-FILE
Set Word = CreateObject("word.basic") ' Set Word
Word.fileopen WrdBestand ' opent een Word document met het Path & Naam file & extensie
Word.appshow ' toont het document
With Range(KL & RijNummer)
Set C = .Comment
On Error GoTo 0
If C Is Nothing Then
MsgBox ("2 Er is geen comment"), vbExclamation
VarComment = " " ' een spatie doorgeven anders foutmelding!
Else
VarComment = C.Text
End If
End With
For Each cl In Selection.Cells
aantal = 0
For i = 1 To Len(VarComment)
If Mid(VarComment, i, 1) = vbLf Then ' laatste regel een vbLf
aantal = aantal + 1
If aantal = 1 Then pos1(1) = aantal
If aantal > 1 Then pos1(aantal) = (pos1(aantal - 1) + pos2(aantal - 1) + 1)
pos2(aantal) = i - pos1(aantal)
veld(aantal) = Mid(VarComment, pos1(aantal), pos2(aantal))
If i = Len(cl) Then Exit For
End If
If i = Len(VarComment) And aantal > 0 Then ' één regel zonder vbLf
aantal = aantal + 1
pos1(aantal) = (pos1(aantal - 1) + pos2(aantal - 1) + 1)
pos2(aantal) = (i + 1) - pos1(aantal)
veld(aantal) = Mid(VarComment, pos1(aantal), pos2(aantal))
End If
If i = Len(VarComment) And aantal = 0 Then ' twee regels één met vbLf en laatste zonder vbLf
aantal = aantal + 1
pos1(aantal) = (pos1(aantal - 1) + pos2(aantal - 1) + 1)
pos2(aantal) = (i + 1) - pos1(aantal)
veld(aantal) = Mid(VarComment, pos1(aantal), pos2(aantal))
End If
Next i
With GetObject(WrdBestand) ' Update variabelen van Excel --> Word doc.
For i = 1 To aantal
.Variables("Veld" & i) = veld(i)
.Fields.Update
Next i
End With
Next
Uit:
End Sub
Thanks Edmoor leer weer steeds bij

Cow18, morgen die van jouw proberen en snb
Nu even rust

Laatst bewerkt: