Schrijf celinhoud naar bestand

Schrijf celinhoud naar bestand C:\temp\textfile.html

Stel, je hebt in cel A1 de volgende tekst staan en je wilt die tekst naar een bestand schrijven.
“Lorem ipsum dolor sit amet, consectetur adipisicing elit,[ . . . ] sunt in culpa qui officia deserunt mollit anim id est laborum.”

Function Schrijf_Naar_Bestand(strCelInhoud As String) As Boolean
    Const LogFileName As String = "C:\temp\textfile.html"
    Dim FileNum As Integer
    
    'Volgende bestandsnummer
    FileNum = FreeFile
    
    'Maakt bestand aan indien niet aanwezig
    Open LogFileName For Append As #FileNum
    
    'Schrijft informatie weg aan het einde van het bestand
    Print #FileNum, strCelInhoud
    
    'Sluit het bestand
    Close #FileNum
    
    'Gelukt
    Schrijf_Naar_Bestand = True
End Function

1. Kopieer de bovenstaande code
2. Open een nieuwe werkmap
3. Druk op de toetscombinatie ALT + F11 om de Visual Basic Editor te openen
4. Druk op de toetscombinatie ALT + N om het menu Invoegen te openen
5. Druk op M om een standaard module in te voegen
6. Daar waar de cursor knippert voeg je de code in middels Ctrl + V
7. Druk op de toetscombinatie ALT + Q om de Editor af te sluiten en terug te keren naar Excel
8. Plaats in een andere cel de volgende functie: =Schrijf_Naar_Bestand(A1)

Leave a Reply

Your email address will not be published. Required fields are marked *