Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 11.4   11.5   12.0   12.1   12.2   12.3   12.4   12.5   13.0   13.1    Statistic    FMM    Blog  

WordFile.ReplaceTag

Replaces a placeholder with text.

Component Version macOS Windows Linux Server iOS SDK
WordFile 5.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "WordFile.ReplaceTag"; WordFile; Placeholder { ; Text; All } )   More

Parameters

Parameter Description Example Flags
WordFile The reference number of the open word file. $wordFile
Placeholder The name of the placeholder.

In plugin version 7.4 and newer case insensitive for ASCII characters.
"City"
Text The new text. "New York" Optional
All Pass 1 to replace all placeholders with same text. 1 Optional

Result

Returns OK or error.

Description

Replaces a placeholder with text.
The place holder in the document must start with « and end with » characters. The place holder you pass here, should not have those quotes.
If you need to replace multi line text like addresses, please use several placeholders, at least one per line. Or for newer plugin pass text with new lines, but that will only work for main text and not headers.

Version 7.0 and newer can handle multi line text better for normal paragraphs. It creates for you new paragraphs for each line in the new text.

If you change font or style of the text within the marker, it will not be recognized. So please keep all text between and including the « and » markers (or whatever is configured) within the same font style.

Examples

Replaces placeholder with text:

Set Variable [$r; Value:MBS("WordFile.ReplaceTag"; $WordFile; "City"; "Nickenich")]

Replaces all placeholder with text:

Set Variable [$r; Value:MBS("WordFile.ReplaceTag"; $WordFile; "City"; "Nickenich"; 1)]

Replace some tags:

# load from container
Set Variable [ $wordfile ; Value: MBS( "WordFile.OpenContainer"; WordFile::Input ) ]
If [ MBS("ISError") ]
    Show Custom Dialog [ "Error" ; $wordFile ]
    Exit Current Script [ Result: ]
End If
# replace placeholders from one record
Set Variable [ $r ; Value: MBS( "WordFile.ReplaceTag"; $WordFile; "FG_Nr"; WordFile::FG_Nr.) ]
Set Variable [ $r ; Value: MBS( "WordFile.ReplaceTag"; $WordFile; "P_Name"; WordFile::P_Name) ]
Set Variable [ $r ; Value: MBS( "WordFile.ReplaceTag"; $WordFile; "P_Vorname"; WordFile::P_Vorname) ]
# write to desktop
Set Variable [ $DesktopPath ; Value: MBS("Folders.UserDesktop") ]
Set Variable [ $FilePath ; Value: MBS( "Path.AddPathComponent"; $DesktopPath; "test output.docx" ) ]
Set Variable [ $r ; Value: MBS( "WordFile.WriteFile"; $WordFile; $FilePath ) ]
Set Variable [ $r ; Value: MBS( "Files.LaunchFile"; $FilePath ) ]
# clean up
Set Variable [ $r ; Value: MBS("WordFile.Release"; $WordFile) ]

See also

Release notes

  • Version 12.5
    • Fixed problem in WordFile.ReplaceTag with all = true, where it returned error, but replaced tags.
  • Version 9.4
    • Fixed a bug in WordFile.ReplaceTag where it would not update the modified XML correctly for replace in header section.
  • Version 9.2
  • Version 7.4
  • Version 7.2
  • Version 7.0
    • Changed WordFile.ReplaceTag to create multiple paragraphs if text to replace contains multiple lines and is part of a normal text paragraph.

Example Databases

Blog Entries

This function checks for a paid license.

Created 5th November 2015, last changed 8th August 2021


WordFile.RemoveTableRow - WordFile.SetCaseless

💬 Ask a question or report a problem


Start Chat