Copy TIA Portal STL/SCL Code to Word with Syntax Highlighting
When a thesis, technical report, FRS, or design review document needs to include the actual source code of an S7-1200, S7-1500, S7-300, or S7-400 program, the engineer must convert the on-screen colors of TIA Portal (green comments, blue keywords, red errors, gray operators) into a portable format that Microsoft Word can render. The native copy/paste clipboard path strips the language coloring because Word's default content type for pasted text is Unicode Text (no formatting). This article documents five reliable workflows to retain color, indentation, and the visual style of TIA Portal V17 through V20, with focus on the supported STL (.awl) and SCL (.scl) text source formats.
1. Why the Default Copy/Paste Loses Colors
When you mark a block or network in TIA Portal, press Ctrl+C, and paste into Word, TIA transfers the content as plain text. The TIA editor uses an internal RTF-like format that Word can interpret for Code blocks in the same TIA Portal instance, but it does not carry the language color attributes to an external Word document. The result is monochrome text. The two methods that work universally are:
- Round-trip the code through a syntax-highlighting text editor that supports Rich Text Format (RTF) export.
- Use the TIA Portal Generate source from blocks function to emit a standalone
.awlor.sclfile, then highlight that file with a third-party tool.
2. Prerequisites
| Tool | Version | Role | License |
|---|---|---|---|
| SIMATIC TIA Portal | V17, V18, V19, or V20 | Source of the PLC project | STEP 7 Professional |
| Notepad++ | v8.6.4 or later (64-bit recommended) | Syntax highlighting + RTF export | Free, GPL |
| NppExport plugin | Bundle with Notepad++ | Converts highlighted code to RTF/HTML | Free, GPL |
| Microsoft Word | 2016, 2019, 2021, 365 | Target document editor | Microsoft 365 / Office LTSC |
| Visual Studio Code (optional) | 1.85 or later | Alternative editor with SCL extensions | Free, MIT |
Reference: Copying code examples into the program - TIA Portal V20 confirms that the TIA Portal Help system provides a Copy button for embedded sample programs only, not for project blocks. Project blocks require the workflows below.
3. Method 1 - Generate Source from Blocks + Notepad++ + NppExport (Recommended)
This is the most robust workflow. It produces a faithful copy of the block including the header (author, family, version, block title) and a colored RTF that pastes cleanly into Word.
3.1 Export the STL/SCL source from TIA Portal
- Open the project in TIA Portal and expand the Program blocks container of the target S7 CPU.
- Right-click a single block, a multi-selection of blocks, or the Program blocks folder.
- Choose Generate source from blocks from the context menu. TIA opens the Generate source dialog.
- Specify an Object name for the generated source file (for example
Thesis_Appendix). The file extension is set automatically by the language:.sclfor SCL,.awlfor STL,.srffor generic TIA source. - Click OK. The source file appears in the External source files folder of the project tree.
- Right-click the new source file and select Open in editor, or right-click and choose Export to file if you want a standalone text file on disk.
3.2 Build the colored file in Notepad++
- Install Notepad++ using the default 64-bit installer. The NppExport plugin is bundled with the standard distribution and does not need a separate download.
- Drag the exported
.awlor.sclfile from Windows Explorer onto the Notepad++ window, or use File → Open. - From the Language menu, select a C-family style that approximates the SCL/STL grammar:
- For SCL: choose Language → C → C++. The SCL tokens
IF,THEN,ELSE,END_IF,CASE,OF,FOR,WHILE,REPEAT,UNTILare highlighted as keywords (blue), numeric literals and string literals are recognized (orange/red), and comments starting with//or(*...*)are colored (green). - For STL: choose Language → C. STL operators
A,AN,O,ON,=,S,R,L,T,JU,JCrender as identifiers (typically black/blue) while//comments become green.
- For SCL: choose Language → C → C++. The SCL tokens
- Verify the highlighting by scrolling. If comments are not green, ensure Settings → Preferences → Language → Treat backslash as escape character is configured to your preference and that the file encoding is UTF-8 (default).
3.3 Export the colored file as RTF
- From the Plugins → NppExport menu, select Copy RTF to clipboard. NppExport walks the lexer state of every visible token and assembles a complete RTF stream with the foreground colors used by the active language.
- Switch to Word, place the cursor at the desired insertion point, and press
Ctrl+V. Word inserts the code as an RTF-formatted fragment. The text retains the green/blue color scheme of the Notepad++ lexer. - Optionally select the pasted block and apply a Word style such as No Spacing with a fixed-width font (Consolas or Cascadia Code, 9 pt is a common thesis convention). The font swap does not destroy the RTF colors because color is stored as a separate RTF attribute.
.rtf file (for example, to attach to a submission portal), use Plugins → NppExport → Export to RTF instead of Copy to clipboard. The resulting file can be opened directly in Word, LibreOffice Writer, or any RTF-capable editor.4. Method 2 - Build a Custom Notepad++ UDL for TIA Colors
The C / C++ language profile gets the syntax 80% right, but STL and SCL have tokens that C ignores (for example := as a single assignment operator, or the # intermediate marker). To reproduce the exact TIA Portal palette, build a User Defined Language (UDL) profile.
4.1 Create the UDL
- In Notepad++, choose Language → Define your language....
- Click Create new... and name it
SCL_STL_TIA. - In the Keywords tab, add the SCL/STL keyword lists. Use the first list for instruction keywords and the second for type keywords:
- List 1:
IF THEN ELSE ELSIF END_IF CASE OF END_CASE FOR TO BY END_FOR WHILE DO END_WHILE REPEAT UNTIL END_REPEAT RETURN EXIT GOTO LABEL - List 2:
BOOL BYTE WORD DWORD INT DINT REAL S5TIME TIME DATE CHAR STRING VOID - List 3: STL bit/word operators:
A AN O ON X XN S R = L T JU JC JCN JZ JP JM JO JL JC)(note: simplify to the operators you actually use)
- List 1:
- In the Operators tab, enter the SCL compound operators so that
:=,<>,<=,>=,AND,OR,NOT,XOR,MODare recognized. UDL also supports Delimiters 1..8 for scope brackets ((,),[,],{,}). - In the Comment & Number tab, set:
- Line comment:
// - Block comment open:
(* - Block comment close:
*) - Number style: check Decimal, Hexadecimal, Octal
- Line comment:
- Match TIA Portal's default color scheme: green (
#008000) for line and block comments, blue (#0000FF) for keywords, dark red (#800000) for numbers, dark gray (#808080) for operators, black for default. UDL exposes a color picker for each category. - Click Save As... and store the UDL as
SCL_STL_TIA.xmlin%APPDATA%\Notepad++\userDefineLangs.
After saving, restart Notepad++. The UDL appears in the Language menu and can be associated with the .awl and .scl extensions via Settings → Style Configurator → Language: SCL_STL_TIA. Repeat Method 1 from step 3.3 to obtain an RTF with the correct TIA palette.
Reference for the UDL XML schema: UDL 2.1 documentation (author maintained by the Notepad++ community; use the schema as the authoritative XML structure).
5. Method 3 - Visual Studio Code with SCL Extension
For engineers who already use VS Code for SCL editing, the modern alternative to Notepad++ is to keep the source file open in Code and copy through the editor. VS Code's default keybinding Ctrl+Shift+C copies the selection with no syntax highlighting, but the workflow below preserves color by exporting the file as an HTML or PDF first.
- Install the Siemens SCL (S7 Structured Control Language) extension from the Visual Studio Marketplace. This extension provides grammar-based tokenization for SCL files.
- Open the generated
.sclfile with File → Open File.... - Choose a theme that matches the TIA palette. The default Light+ and Dark+ themes provide the closest visual match to the TIA Portal editor. For exact color parity, import the Siemens Theme from the same extension's README, or use Preferences → Color Theme → Light (Visual Studio).
- Use the command palette (
Ctrl+Shift+P) and run Markdown PDF: Export (html) (requires the Markdown PDF extension), or run Print to a Microsoft Print to PDF printer. The HTML output retains all the token colors. - Open the resulting HTML in a browser, select all (
Ctrl+A), copy, and paste into Word. Alternatively, drag the HTML file into a Word document; Word imports the styled<span>blocks as natively colored text.
:=, %IW0, DB10) by default. Configure the language server or add a tmLanguage snippet to the user snippet directory if your thesis shows extensive I/O addressing.6. Method 4 - TIA Portal Built-in Copy and Paste-as-RTF
For short snippets (one network, one function) the fastest path uses TIA's own copy commands without leaving the engineering environment.
- Open the block and select the network or code region you want to export.
- Right-click and choose Copy. TIA puts the selection on the clipboard in an internal RTF variant.
- In Word, place the cursor and use Home → Paste → Paste Special... and select Formatted Text (RTF) instead of the default Keep Source Formatting paste. In some Word versions, choose Unformatted Unicode Text and then re-apply a code style.
- If colors do not transfer, the block was selected with the keyboard (
Ctrl+Ain the editor) rather than the right-click Copy command. Some TIA Portal versions only emit color when the right-click context menu is used.
Reference: TIA Portal V20 Help - Copying code examples into the program describes the Copy button in the help system. Project blocks use the right-click Copy function described above.
7. Method 5 - Screen Capture Fallback (for LAD/FBD)
When the code to be documented is a LAD or FBD network, no text-based workflow applies because the logic is graphical. Use a screen capture instead.
- Hide the project tree and the detail pane in TIA Portal to maximize the editor view: View → Project Tree → Collapse or simply press
F11for full-screen on supported configurations. - Set the editor zoom to 100% or higher. View → Zoom... opens a slider that can go up to 400%.
- Press
Win+Shift+Sto invoke the Windows Snipping Tool, drag a rectangle around the network, and paste into Word withCtrl+V. Word treats the capture as a PNG and you can crop, annotate, and caption it directly. - For multi-page output, use the free Microsoft Snip & Sketch tool or the third-party Greenshot utility to capture and label each network.
Use this method only for graphical networks; the resulting image is not searchable and does not meet accessibility guidelines for screen readers. For text-based STL or SCL, prefer Method 1.
8. Comparison Matrix
| Method | Output type | Color fidelity | Editable in Word | Best use case | Effort |
|---|---|---|---|---|---|
| 1. Generate source + NppExport | RTF in clipboard / .rtf file |
High (C/C++ palette) | Yes - colored text fragment | Full thesis appendix, multiple blocks | Medium |
| 2. Custom UDL + NppExport | RTF with exact TIA palette | Very high | Yes - colored text fragment | When corporate style requires TIA colors | High (one-time setup) |
| 3. VS Code + HTML export | HTML / PDF | High (theme-dependent) | Yes - HTML imports as styled spans | Engineers already in VS Code ecosystem | Medium |
| 4. TIA right-click Copy | Internal RTF variant | Medium (varies by version) | Yes | Single network, quick copy | Low |
| 5. Screen capture | PNG image | Pixel-perfect | No - image only | LAD/FBD networks, signatures, comments overlay | Low |
9. Word-Side Configuration for Best Results
Regardless of which method produces the colored text, configure Word to make the document portable and to meet typical thesis formatting requirements.
- Define a character style named Code: Home → Styles → Create a Style → Character → Font: Consolas, 9 pt, 1.15 line spacing, no proofing.
- Disable automatic spell-check on code by selecting the pasted code and choosing Review → Language → Set Proofing Language → English (no proofing) or simply Do not check spelling or grammar.
- Disable smart quotes and autocorrect: File → Options → Proofing → AutoCorrect Options and uncheck Replace text as you type while editing code.
- For the table of contents, do not include code fragments. Use a heading style (Heading 3) for the appendix section title and the Code character style for the inline content.
- When the final document is exported to PDF (File → Save As → PDF), verify that the PDF preserves the RTF colors by opening the PDF in a viewer and checking the text selection - the selected text should match the visible color attribute.
10. Verification Checklist
| Step | Expected result | What to check |
|---|---|---|
| Generate source from blocks |
.scl or .awl file appears under External source files
|
Right-click → Open in editor shows the block contents |
| Apply language in Notepad++ | Keywords turn blue, comments turn green | Scroll through file and confirm a representative IF and a // comment |
| NppExport RTF copy | Clipboard contains non-empty RTF | Paste into Notepad and inspect first bytes for {\rtf1
|
| Paste into Word | Colored text appears with monospace font | Highlight a green comment in Word; the font color should display as green in the ribbon |
| PDF export | Colors survive the export | Open the PDF and select a comment - the text should remain green |
| Character count | Same number of characters as the TIA block (no loss of // lines) |
Word's word count vs TIA's block statistics |
11. Troubleshooting
| Symptom | Likely cause | Remedy |
|---|---|---|
| Pasted text is black-and-white | NppExport not installed or wrong menu chosen | Re-open the file in Notepad++ and use Plugins → NppExport → Copy RTF to clipboard (not Copy all formats to clipboard) |
| Comments are not green | Active language profile does not recognize // or (*...*)
|
Switch to the custom UDL (Section 4) or use C++ and verify Settings → Preferences → Language → C++ → Treat keyword as comment |
| Special characters become mojibake (e.g. umlauts) | Encoding mismatch between Notepad++ and Word | Set Encoding → Convert to UTF-8 (without BOM) in Notepad++ before exporting; in Word use File → Options → Advanced → Confirm file format conversion on open and select UTF-8 on first prompt |
| Word auto-formats straight quotes to curly quotes | Word autocorrect active | Select the block → Review → Language → Set proofing language → Do not check spelling |
| Generated source file is empty | Block was not compiled before export | Right-click the block → Compile → Software (only) and then re-run Generate source from blocks |
.scl file opens in TIA as a project, not as text |
File association hijacked by TIA | Open Notepad++ first, then File → Open; or use Open with... from Windows Explorer |
| PDF export loses color | Word's PDF/A settings strip color streams | Choose Standard instead of Minimum size or PDF/A in Save As → PDF |
12. Field-Proven Tips and Caveats
-
One segment per network, one block per appendix sub-section. If a function block contains 40 networks, copy the entire block rather than network by network. TIA's Generate source from blocks preserves the network numbering and the closing
END_FUNCTION_BLOCKline in the correct order. -
UDL portability. The
.xmlUDL file is plain text and can be checked into a thesis repository. Commit it next to the thesis source for repeatable builds. -
Access to NppExport on locked-down PCs. Some corporate installations lock
%APPDATA%. In that case, install Notepad++ in portable mode (the ZIP distribution) into a user-writable folder and run the executable directly. The NppExport plugin is included inplugins\NppExportand works in portable mode without registration. - Long block printout. For a 200-page thesis appendix, use the RTF export and File → Print in Word with Paper size: A4 and Margins: Narrow to fit approximately 60 lines per page in Consolas 8 pt.
- Copyright and confidentiality. A thesis appendix is a public document. Verify with your thesis supervisor that the project does not contain proprietary code before exporting.
- Alternatives to Microsoft Word. The same NppExport RTF opens in LibreOffice Writer and in WordPad with full color preservation. Use this if Microsoft Office is not available.
13. Frequently Asked Questions
Does the right-click Copy in TIA Portal preserve colors when pasted into Word?
It depends on the TIA Portal version and the active paste mode in Word. The internal clipboard format includes RTF in V17 and later, but Word's default Keep Source Formatting often renders the result as monochrome. Use Paste Special → Formatted Text (RTF) or switch to the NppExport workflow for reliable color transfer.
Can I export SCL from an S7-1200 / S7-1500 project directly to Word?
Yes. SCL is one of the two first-class text languages in TIA Portal V17, V18, V19, and V20. Use Program blocks → right-click → Generate source from blocks, which produces a .scl file that you open in Notepad++ and export via NppExport as RTF for Word.
Is STL still supported for the appendix of a 2024/2025 thesis?
STL is supported on S7-300/400 and on S7-1500 with a compatibility flag, but it is no longer taught as a primary language. SCL has been the recommended text language since the S7-1200 generation. If your thesis is historical, STL is fine; if it is forward-looking, switch the examples to SCL.
Why are my comments not green in the Notepad++ RTF export?
Notepad++ requires an active lexer to detect the // or (*...*) sequence. The default Normal Text profile does not apply any color. Select Language → C++ for SCL or build a custom UDL as described in Section 4 to assign green to the comment category.
What is the maximum block size that can be exported with NppExport?
NppExport operates on the text buffer of the current document, not on a fixed character limit. In practice, a 1 MB .scl file (roughly 600,000 lines) copies successfully to the clipboard. For very large appendices, prefer the Export to RTF option, which writes a file directly and is not constrained by the clipboard size limit.