Platforms to show: All Mac Windows Linux Cross-Platform
Back to WordFileMBS class.
WordFileMBS.addMediaFile(name as string, content as string)
Function:
Adds a media file image.
Notes:
You can use this function to add a new image.
You need to add the reference in XML yourself to let the image appear somewhere in the document.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 19.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
You can use this function to add a new image.
You need to add the reference in XML yourself to let the image appear somewhere in the document.
WordFileMBS.Append(other as WordFileMBS, AddPageBreak as boolean = false) as Boolean
Function:
Appends one word file text to other.
Notes:
This function takes document part from other word file and copies it’s xml nodes to the current document.
Please only copy from one document to other if they both are made from same template, so internal IDs for styles match.
Returns true on success or false on failure.
Added AddPageBreak parameter in version 19.2. If true, we add a page break between the old and new parts.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 17.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
This function takes document part from other word file and copies it’s xml nodes to the current document.
Please only copy from one document to other if they both are made from same template, so internal IDs for styles match.
Returns true on success or false on failure.
Added AddPageBreak parameter in version 19.2. If true, we add a page break between the old and new parts.
WordFileMBS.AppendTableRow(tag as string) as Integer
Function:
Duplicates a table row containing a placeholder.
Notes:
If you have tables in your template word file and you like to duplicate it, this function can do that and add the new row on the end of the table.
Returns Values
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 17.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
If you have tables in your template word file and you like to duplicate it, this function can do that and add the new row on the end of the table.
Returns Values
0 | success |
1 | Tag not found. |
2 | Tag found, but not in a table. |
3 | Missing main document part. |
WordFileMBS.Constructor Private
Function:
The private constructor.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | Desktop only |
WordFileMBS.Contains(findText as string) as boolean
Function:
Checks if some text exists in the document.
Notes: This is like HasTag function, but doesn't require markers around the text in the document.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 21.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes: This is like HasTag function, but doesn't require markers around the text in the document.
WordFileMBS.DuplicateTableRow(tag as string) as Integer
Function:
Duplicates a table row containing a placeholder.
Notes:
If you have tables in your template word file and you like to duplicate it, this function can do that and add the new row on just after the row to copy.
Returns Values
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 17.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
If you have tables in your template word file and you like to duplicate it, this function can do that and add the new row on just after the row to copy.
Returns Values
0 | success |
1 | Tag not found. |
2 | Tag found, but not in a table. |
3 | Missing main document part. |
WordFileMBS.FieldNames as String()
Function:
Queries field names in the file.
Notes: This looks for form fields in a word file.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 17.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes: This looks for form fields in a word file.
WordFileMBS.GetFieldText(fieldName as string, byref text as String) as boolean
Function:
Queries field value.
Notes:
The plugin looks for the field with given name and queries it's text.
Returns true if field was found.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 17.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
The plugin looks for the field with given name and queries it's text.
Returns true if field was found.
WordFileMBS.HasTag(tag as string) as boolean
Function:
Checks if a tag exists.
Notes:
The place holder in the document must start with « and end with » characters. The place holder you pass here, should not have those quotes.
Returns true on success or false on failure.
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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
The place holder in the document must start with « and end with » characters. The place holder you pass here, should not have those quotes.
Returns true on success or false on failure.
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.
WordFileMBS.MediaFile(name as string) as String
Function:
Queries or replaces the content of a media file.
Example:
Notes:
You can use this to extract images from word file.
Or to replace a placeholder image with the real image.
For replacement please make sure file type and dimensions match.
Raises KeyNotFoundException if media file with given name is not found.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | Wordfile | MBS Tools Plugin | 16.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Example:
Dim word As WordFileMBS // open word document
// name one
Dim name As String = "image1.jpg"
// or pick from list
'Dim MediaFiles() As String = word.MediaFiles
'Dim name As String = MediaFiles(0) // first one
// load image
Dim ImageFile As FolderItem = SpecialFolder.Desktop.Child("new.jpg")
Dim ImageStream As BinaryStream = BinaryStream.Open(ImageFile)
Dim ImageData As String = ImageStream.Read(ImageStream.Length)
word.MediaFile(name) = ImageData
You can use this to extract images from word file.
Or to replace a placeholder image with the real image.
For replacement please make sure file type and dimensions match.
Raises KeyNotFoundException if media file with given name is not found.
(Read and Write computed property)
WordFileMBS.MediaFiles as String()
Function:
Lists the media files in the word document.
Example:
Notes:
e.g. image1.png
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 16.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Example:
// read a word file:
Dim file As New FolderItem("c:\tmp\test.docx", folderitem.PathModes.Native)
Dim wordStream As BinaryStream = BinaryStream.Open(file)
Dim wordData As String = wordStream.Read(wordStream.Length)
wordStream.close
Dim word As WordFileMBS = WordFileMBS.OpenData(wordData)
// now show list of files in message box
Dim MediaFiles() As String = word.MediaFiles
MessageBox Join(MediaFiles, EndOfLine)
WordFileMBS.Parts as String()
Function:
Queries names of the parts of the document.
Example:
Notes:
This may tell you how many headers/footers we found in a docx file.
e.g. "footer1", "header1", "document".
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 16.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Example:
dim f as FolderItem = GetFolderItem("test.docx")
dim b as BinaryStream = BinaryStream.Open(f)
dim d as string = b.Read(b.Length)
dim w as WordFileMBS = WordFileMBS.OpenData(d)
MsgBox w.XML("footer1")
This may tell you how many headers/footers we found in a docx file.
e.g. "footer1", "header1", "document".
WordFileMBS.RemoveTableRow(tag as string) as Integer
Function:
Removes a table row containing a placeholder.
Notes:
If you have tables in your template word file and you only fill some rows, you can remove superfluous rows using this function.
Returns Values
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 17.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
If you have tables in your template word file and you only fill some rows, you can remove superfluous rows using this function.
Returns Values
0 | success |
1 | Tag not found. |
2 | Tag found, but not in a table. |
3 | Missing main document part. |
WordFileMBS.ReplaceTag(tag as string, text as string = "", All as boolean = false) as boolean
Function:
Replaces a placeholder with text.
Example:
Notes:
The place holder in the document must start with « and end with » characters. The place holder you pass here, should not have those quotes.
Returns true on success or false on failure.
If you need to replace multi line text like addresses, please use several placeholders, at least one per line.
Version 17.0 and newer can handle multi line text better for normal paragraphs with Chr(13). 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.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Example:
dim f as FolderItem = GetFolderItem("test.docx")
dim b as BinaryStream = BinaryStream.Open(f)
dim d as string = b.Read(b.Length)
dim w as WordFileMBS = WordFileMBS.OpenData(d)
if w.ReplaceTag("FirstName", "Peter") then
if w.ReplaceTag("LastName", "Miller") then
f = GetFolderItem("output.docx")
if w.WriteFile(f) then
MsgBox "OK"
end if
end if
end if
The place holder in the document must start with « and end with » characters. The place holder you pass here, should not have those quotes.
Returns true on success or false on failure.
If you need to replace multi line text like addresses, please use several placeholders, at least one per line.
Version 17.0 and newer can handle multi line text better for normal paragraphs with Chr(13). 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.
Some examples using this method:
WordFileMBS.SetFieldText(fieldName as string, text as String) as boolean
Function:
Sets field value.
Notes:
The plugin looks for the field with given name and sets it's text.
Returns true if field was found.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 17.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
The plugin looks for the field with given name and sets it's text.
Returns true if field was found.
WordFileMBS.SetMarkers(openMarker as String, closeMarker as String) as boolean
Function:
Sets the markers to look for before/after a tag.
Notes:
Default are « and ».
Should be different and not empty.
Returns true on success or false on failure.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 16.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
Default are « and ».
Should be different and not empty.
Returns true on success or false on failure.
WordFileMBS.Substitute(findText as string, replaceText as string = "", All as boolean = false) as boolean
Function:
Replaces some text in the document with new text.
Notes:
Like ReplaceTag function, but without markers around the tag.
Handles multi line text better for normal paragraphs with Chr(13). It creates for you new paragraphs for each line in the new text.
If you change font or style of the text within the find text, it will not be recognized. So please keep all text within the same font style.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 21.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
Like ReplaceTag function, but without markers around the tag.
Handles multi line text better for normal paragraphs with Chr(13). It creates for you new paragraphs for each line in the new text.
If you change font or style of the text within the find text, it will not be recognized. So please keep all text within the same font style.
WordFileMBS.Tags as String()
Function:
Queries list of tags.
Notes:
Depends on the start/end markers set with OpenMarker/CloseMarker properties.
Can be very useful for debugging to query list of tags found in the document.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 22.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
Depends on the start/end markers set with OpenMarker/CloseMarker properties.
Can be very useful for debugging to query list of tags found in the document.
WordFileMBS.WriteFile(path as folderItem) as boolean
Function:
Writes a file to disk.
Example:
Notes:
File extension should be correct, either docx or xml depending on what you loaded.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Wordfile | MBS Tools Plugin | 15.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Example:
dim f as FolderItem = GetFolderItem("test.docx")
dim b as BinaryStream = BinaryStream.Open(f)
dim d as string = b.Read(b.Length)
dim w as WordFileMBS = WordFileMBS.OpenData(d)
if w.ReplaceTag("FirstName", "Peter") then
if w.ReplaceTag("LastName", "Miller") then
f = GetFolderItem("output.docx")
if w.WriteFile(f) then
MsgBox "OK"
end if
end if
end if
Some examples using this method:
WordFileMBS.XML(part as String) as String
Function:
Queries/Sets XML for a part.
Notes:
See Parts array for possible parts.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | Wordfile | MBS Tools Plugin | 16.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
See Parts array for possible parts.
(Read and Write computed property)
See also:
The items on this page are in the following plugins: MBS Tools Plugin.
