0% found this document useful (0 votes)
7 views1 page

Format Word Document for Certificates

The document contains a VBA function named 'FormatCertificateWord' that formats the content of a Word document specified by a file path. It cleans up the text by replacing tabs and non-breaking spaces, normalizes specific labels by appending a colon, and returns the formatted text. The function ensures that a Word application instance is created if it doesn't already exist.

Uploaded by

Majdi Belguith
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Format Word Document for Certificates

The document contains a VBA function named 'FormatCertificateWord' that formats the content of a Word document specified by a file path. It cleans up the text by replacing tabs and non-breaking spaces, normalizes specific labels by appending a colon, and returns the formatted text. The function ensures that a Word application instance is created if it doesn't already exist.

Uploaded by

Majdi Belguith
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Attribute VB_Name = "Module_FormatWord"

Option Explicit

Public Function FormatCertificateWord(path As String) As String


Dim doc As Object
Dim rawText As String

If gWordApp Is Nothing Then


Set gWordApp = CreateObject("[Link]")
[Link] = False
End If

Set doc = [Link](path, ReadOnly:=True)


rawText = [Link]
[Link] False

' ----- Nettoyage -----


rawText = Replace(rawText, vbTab, " ")
rawText = Replace(rawText, Chr(160), " ")
rawText = Replace(rawText, vbCr, vbLf)
rawText = Replace(rawText, vbLf & vbLf, vbLf)

' ----- Normalisation des labels -----


Dim lbl
For Each lbl In Array("Cert_Ref", "Rev", "Cert_Typ", "Status", "Issuer", _
"Issue date", "Issued to", "Equipment", "Component", _
"IEC Standard(s)", "Link")
rawText = Replace(rawText, lbl, lbl & ":")
Next lbl

FormatCertificateWord = rawText
End Function

You might also like