Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
WordFile.ReplaceTag
Replaces a placeholder with text.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
WordFile | 5.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
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
- Files.Launch
- Files.LaunchFile
- Folders.UserDesktop
- IsError
- Path.AddPathComponent
- WordFile.AppendTableRow
- WordFile.OpenContainer
- WordFile.Release
- WordFile.Substitute
- WordFile.WriteFile
Release notes
- Version 14.3
- Fixed the WordFile.ReplaceTag function, which broke in 14.2.
- Version 14.2
- Improved WordFile.ReplaceTag and WordFile.Substitute functions to remove control characters from replacement text to avoid creating broken word files.
- Version 13.4
- Fixed a problem with WordFile.ReplaceTag and WordFile.Substitute functions when passing in NULL characters in the text.
- 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
- Changed WordFile.ReplaceTag to look for tags in document properties.
- Version 7.4
- Changed WordFile.ReplaceTag to be case insensitive for ASCII characters.
- Version 7.2
- Fixed bug in WordFile.ReplaceTag with several tags in one line.
- 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
- MBS FileMaker Plugin, version 14.3pr1
- MBS FileMaker Plugin, version 14.2pr1
- MBS FileMaker Plugin, version 13.4pr7
- MBS FileMaker Plugin, version 12.5pr1
- MBS FileMaker Plugin, version 9.4pr5
- MBS FileMaker Plugin, version 9.2pr2
- MBS FileMaker Plugin, version 7.4pr3
- MBS FileMaker Plugin, version 7.2pr1
- MBS FileMaker Plugin, version 7.0pr1
FileMaker Magazin
This function checks for a license.
Created 5th November 2015, last changed 8th August 2021