0

In MS Word I draw rectangle as Autoshape with Win32com, but I can't understand how to change its colors with FillFormat.

word = win32com.client.gencache.EnsureDispatch('Word.Application')
document = word.ActiveDocument
rect = shapes.AddShape(1, 56.7, 14.2, 524.4, 813.5)

By default it provides solid blue figure. What I need is transparent rectangle with black thick border.

Sib
  • 404
  • 4
  • 16
  • Have you tried recording creating that Shape in a Word VBA macro, to get the necessary objects and properties for what you need? – Cindy Meister May 11 '19 at 13:54
  • Already tried. For some unknown reasons macros recording in MS Word makes selection of autoshape very difficult, even if I manage to select it and to change the background color - my macros records only "selection" action and nothing more. – Sib May 11 '19 at 14:26

1 Answers1

1

"Thick border" is not an exact parameter, but based on the assumption that the default border is already "thick", the following sample VBA code illustrates how to remove the fill and change the color of the border:

rect.Fill.Visible = 0  'msoFalse
rect.Line.ForeColor.RGB = RGB(0, 0, 0)

I don't use Python, but it appears from the code in the question to work with the object model the same way VBA does, once it has the connection to the Word application and a Document object...

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
  • Thanks! it finally works for me. Although the second string returned me a mistake in Python, so I replaced `RGB(0, 0, 0)` by `rgbToInt((0, 0, 0))` from this solution https://stackoverflow.com/a/21338319/11358805 – Sib May 11 '19 at 16:12