Search code examples
ms-wordoleword-field

What is difference between \ and \\


I have an embedded word document in my worksheet, names "Rec1"

The fields code are same as below:

{LINK Excel.SheetMacroEnabled.12 "C:\\Documents and Settings\\user\\Desktop\\Salaries\\StaffSalaries.xlsm" مالي!R2C13 \a \f 4 \r  \* MERGEFORMAT}

What is the different and using "\ \" (double BackSlash) character with "\" one?


Solution

  • Word field codes originate in the C programming language. In that language, the backslash is used to indicate what in Office are called "switches" (like parameters). You see this a lot in command-lines, as well.

    So in the LINK field you show us, \a, \f 4, \r and * Mergeformat are telling Word how to manage the field code (more info at https://support.office.com/en-us/article/field-codes-link-field-09422d50-cde0-4b77-bca7-6a8b8e2cddbd?ui=en-US&rs=en-US&ad=US).

    • \a tells the field it should update automatically
    • \f 4 tells Word to maintain Excel's original formatting
    • \r instructs Word to use RTF conversion for displaying the content
    • * are formatting switches, in this case, manually applied formatting should be retained when the field is updated

    Because a single backslash denotes a switch, when you want to pass a literal backslash you need to double it up. This is the case for a file path, for example.