error xlPrimary not defined in Python win32com

后端 未结 2 2084
离开以前
离开以前 2020-12-22 00:39

I keep getting errors where xlCategory, xlValue and xlPrimary are not recognised in my python script.

I am trying to label th

2条回答
  •  感动是毒
    2020-12-22 01:23

    The main reason for this attribute error is because your COM-server has shifted from late-binding (dynamic) to early binding (static).

    • In Late Binding, whenever a method is called, the object is queried for the method and if it succeeds, then the call can be made.
    • In Early Binding, the information of the object model is determined in advance from type information supplied by the object call. Early binding makes use of MakePy. Also, early binding is case sensitive.

    There are two ways to fix this issue:

    1. Use the dynamic module to force your code to work in a late-bound oriented way. Example use:

      "win32com.client.dynamic.Dispatch()" instead of "win32com.client.Dispatch()" 
      
    2. Use camelcase sensitive keywords for the early bound oriented way. Example use:

      "excel.Visible()" instead of "excel.VISIBLE()" or "excel.visible()"
      

    If you want to use variables without case sensitive issues, you should delete the gen_py folder and use win32com.client.Dispatch()

提交回复
热议问题