I would like to convert a VBA
script in win32com
code in order to select and modify property of line shape in excel worksheet.
I am able to select the line (I see the line selected in excel worksheet) but I'm not able to change the property.
Could someone help me?
VBA Code
Sheets("Maps").Select
Sheets("Maps").Shapes.Range(Array(item_in_review_2)).Select
With Selection.ShapeRange.Line
.Weight = 3
If .ForeColor.RGB = RGB(0, 0, 0) Then
.ForeColor.RGB = RGB(0, 255, 0)
Else
.ForeColor.RGB = RGB(255, 0, 0)
End If
End With
This is my code in python
import win32com.client as win32
import os
def rgbToInt(rgb):
colorInt = rgb[0] + (rgb[1] * 256) + (rgb[2] * 256 * 256)
return colorInt
xlApp = win32.gencache.EnsureDispatch('Excel.Application')
xlApp.Visible = True
wb = xlApp.Workbooks.Open('C:\\Users\\xxx\\PycharmProjects\\prova\\Book1.xlsx')
sht = wb.Worksheets('Maps')
OTS_review = 'test'
changeline = sht.Shapes(OTS_review).Select()
changeline.Width = 3
if changeline.ForeColor.RGB == rgbToInt((255,0,0)):
changeline.ForeColor.RGB = rgbToInt((0, 255, 0))
else:
changeline.ForeColor.RGB = rgbToInt((255, 0, 0))
This is error reported
Traceback (most recent call last):
File "C:/Users/xxxx/PycharmProjects/prova/xxx.py", line 18, in changeline.Width = 3
AttributeError: 'NoneType' object has no attribute 'Width'