LoginSignup
umanizer
@umanizer (uma nizer)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

pywin32にてExcel起動しない。。

解決したいこと

pywin32でExcel操作をしたいです。

発生している問題・エラー

jupyter notebook上で動かしています。
ライブラリーインポートしてExcelを起動させようとしたとこで躓きました。。

com_error                                 Traceback (most recent call last)
c:\users\arata\appdata\local\programs\python\python38\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch, clsctx)
     80                 try:
---> 81                         IDispatch = pythoncom.connect(IDispatch)
     82                 except pythoncom.ole_error:

com_error: (-2147221021, '操作を利用できません', None, None)

During handling of the above exception, another exception occurred:

com_error                                 Traceback (most recent call last)
<ipython-input-17-f57ef7dc902d> in <module>
      1 import win32com.client as com
      2 
----> 3 app = com.Dispatch("Excel.Application")
      4 app.Visible = True
      5 app.DisplayAlerts = False

c:\users\arata\appdata\local\programs\python\python38\lib\site-packages\win32com\client\__init__.py in Dispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString, clsctx)
     93   """
     94   assert UnicodeToString is None, "this is deprecated and will go away"
---> 95   dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
     96   return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
     97 

c:\users\arata\appdata\local\programs\python\python38\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatchAndUserName(IDispatch, userName, clsctx)
     96         else:
     97                 userName = str(userName)
---> 98         return (_GetGoodDispatch(IDispatch, clsctx), userName)
     99 
    100 def _GetDescInvokeType(entry, invoke_type):

c:\users\arata\appdata\local\programs\python\python38\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch, clsctx)
     81                         IDispatch = pythoncom.connect(IDispatch)
     82                 except pythoncom.ole_error:
---> 83                         IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
     84         else:
     85                 # may already be a wrapped class.

com_error: (-2146959355, 'サーバーの実行に失敗しました', None, None)

該当するソースコード

import win32com.client as com

app = com.Dispatch("Excel.Application")
app.Visible = True
app.DisplayAlerts = False


自分で試したこと

anacondaが悪さしてるのかと思いanacondaごとpythonをアンインスト―ルしましたが変わらず。
pywinライブラリを入れなおしたりもしましたがうまくいきませんでした。
初心者ですがよろしくお願いします!

0

No Answers yet.

Your answer might help someone💌