I am building a Userform (In Excel) that gives the user the following options on Excel to Word automation:
All these options are inspired by this Microsoft article.
- Update links automatically / manually / break link (\a switch)
- Store graphical data (\d switch)
- Insert as bitmap (\b switch)
- Insert as picture (\p switch)
- Maintain formatting of source file (\f 4 switch)
- Match the formatting of the destination document (\f 5 switch)
- Insert as HTML (\h switch)
- Insert as RTF (\r switch)
- Insert in text-only format (\t switch)
- Insert as Unicode text (\u switch)
- Preserve formatting after update (* MERGEFORMAT switch)
I know I can record a Macro to send each option to Word and then interpret the results, but does anyone know how I can control the syntax sent (maybe as a built string) to Word instead of heavy coding and research for each option above?
Also, does anyone know which options cannot be used with which? For example I can't send as bitmap and as a picture.
The syntax I want to send is:
{ LINK ClassName "FileName" [PlaceReference ] [Switches ] }
For example:
{ LINK Excel.Sheet.8 "C:\\My Documents\\Profits.xls" "Sheet1!R1C1:R4C4" \a \p }
Any advice or assistance would be appreciated.
Thanks.
R
Yes, you can use a "built string". It's probably the simplest way to do it.
The safest way to insert a field in Word is to insert an "empty" field, i.e. one that has type
wdFieldEmpty
rather than the specific typewdFieldLink
, but provide the complete text of the field. Then update it (I have no memory for details so I tend to experiment to see if that is necessary of not).e.g., assuming you have a reference to a
Word.Range
object calledrng
in the word document, and you have a reference to the Word object library, you might use something like this:If you aren't referencing the Word object library, you could use
Some things to consider:
Sheet1!R3C1:R5C3
should either besheetname!RangeInRCFormat
orrangename
. You may need sheetname!rangename for a range that has sheet scope rather than workbook scope and is not in the first sheet.As for the "what you can use with what"
If you need to update an existing LINK field in Word, you as long as you can locate the field, e.g you know it's the 3rs field in the document, you should be able to replace its field code and update the field again, e.g.