Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Download:

Datei 1: x01.dotm

 

 

Der vba Code sucht einen Platzhalter Text im Word Document und ersetzt diesen durch einen anderen Text.

Gezeigt wird:

 

Durchlaufen aller Words in einem Word Dokument

Den gefundendenen Text als Paragraph auswählen

Range Object aus dem Satz bilden

Ersetzten des Text im Range Object

 

 

Vba Code Beispiel

 

Option Explicit On

 

'----< Setup Parameters >----

Const const_Path_Photos_Default As String = "B:\2020"

Const const_int_maxLength_Photos As String = 17

Const Nr_Table_with_Fotos As Integer = 1

Const Show_Filenames As Boolean = True

Const Show_ImageNr As Boolean = True

Const Add_Empty_Textline As Boolean = True

'----</ Setup Parameters >----

 

'=====< BUTTONS >=========

Private Sub btnMarkieren_Click()

    Find_Placeholder()

End Sub

'=====</ BUTTONS >=========

 

 

 

 

Private Sub Find_Placeholder()

    '-----------------< Find_Placeholder() >-----------------

 

    '< init >

    Dim sPlatzhalter As String

    sPlatzhalter = "Platzhalter"

    Dim lenPlaceholder As Integer

    lenPlaceholder = Len(sPlatzhalter)

 

    Dim doc As Document

    Set doc = Application.ActiveDocument

    Selection.MoveStart

    '</ init >

 

    '----< @Loop: Controls >----

    '*loop all Phrases

    'For Each var In doc.Words

    Dim i As Long

    For i = 1 To doc.Words.Count - 2

        Dim var As Variant

        Set var = doc.Words(i)

        If var.Text = "[" Then

            Dim varPlatzhalter As Variant

            Set varPlatzhalter = doc.Words(i + 1)

            If varPlatzhalter = sPlatzhalter Then

                '--< Platzhalter gefunden >--

                Dim range_Platzhalter As Range

                Set range_Platzhalter = var.Paragraphs(1).Range 'satz auswaehlen

                range_Platzhalter.SetRange 1, lenPlaceholder   'markieren

                range_Platzhalter.Text = "ERSETZT"  'ersetzen

                '--</ Platzhalter gefunden >--

            End If

        End If

    Next

    '----</ @Loop: Controls >----

    '-----------------</ Find_Placeholder() >-----------------

End Sub

 

 

 

 

 

Mobile
vba
»
Vba Code: Copy template area
»
Vba Code: Platzhalter finden und ersetzen
»
Insert a line break at the end of a line and then insert text or a table
»
Word: insert characters at the end of a line
»
Text input fields in Word with vba c #
»
Create input fields in Word. C# ContentControls
»
Protect Word programmatically
»
Word vba: find current sentence
»
Word vba: Change document property title dynamically with Textbox Control
»
Word Code: Edit photos and controls in vba

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de