From timr at probo.com Wed Dec 1 03:07:43 2021 From: timr at probo.com (Tim Roberts) Date: Wed, 1 Dec 2021 00:07:43 -0800 Subject: [python-win32] Clipboard Documentation In-Reply-To: <8510f81f-0566-a39c-97ab-689063613bc9@yahoo.com> References: <6415224c-0fcf-dada-cbcf-9c2beecf64aa.ref@bellsouth.net> <6415224c-0fcf-dada-cbcf-9c2beecf64aa@bellsouth.net> <8b9df814-aa88-21ae-c82d-6a835b109068@probo.com> <8510f81f-0566-a39c-97ab-689063613bc9@yahoo.com> Message-ID: On 11/30/21 7:04 AM, gw1500 via python-win32 wrote: > > Thanks for the reply. I read about that but was hoping to use pywin32. > I can see now the folly of that decision. > > I have a working minimal test but am looking for something a bit more > automated. I bring my app window to the top using pywin32 and a line I > need is already highlighted. I can ctrl-c from the keyboard and > pyperclip works just fine. However, since the line is already > highlighted is there a way to get it without user interaction (ctrl-c)? ?I don't know how much trouble you want to go to.? If you can get the window handle of the text box that has your text, you can send a WM_COPY message to it.? With the standard controls, that tells it to do a "copy" operation with the currently selected text. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From maillist at schwertberger.de Wed Dec 1 11:33:03 2021 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Wed, 1 Dec 2021 17:33:03 +0100 Subject: [python-win32] Clipboard Documentation In-Reply-To: <8510f81f-0566-a39c-97ab-689063613bc9@yahoo.com> References: <6415224c-0fcf-dada-cbcf-9c2beecf64aa.ref@bellsouth.net> <6415224c-0fcf-dada-cbcf-9c2beecf64aa@bellsouth.net> <8b9df814-aa88-21ae-c82d-6a835b109068@probo.com> <8510f81f-0566-a39c-97ab-689063613bc9@yahoo.com> Message-ID: <346fb926-3087-01b7-9ab0-6df0a2175521@schwertberger.de> I've been using the code below for 20 years now for text copy & paste. No guarantees, though. Regards, Dietmar def copy_to_clipboard(text, window_handle=0): ??? """copy_to_clipboard(window_handle, text): ??? copy a string to the clipboard.""" ??? win32clipboard.OpenClipboard(window_handle) ??? try: ??????? win32clipboard.EmptyClipboard() ??????? if sys.version_info.major==2: ??????????? is_unicode = isinstance(text, str) ??????? else: ??????????? is_unicode = True ??????? if is_unicode: win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, text) ??????? else: ??????????? win32clipboard.SetClipboardText(text) ??? finally: ??????? win32clipboard.CloseClipboard() _formats = {} def _format_to_number(format): ??? if not format in _formats: ??????? number = win32clipboard.RegisterClipboardFormat(format) ??????? _formats[format] = number ??? return _formats[format] #def copy_from_clipboard(format=win32clipboard.CF_TEXT, window_handle=0): def copy_from_clipboard(format=win32clipboard.CF_UNICODETEXT, window_handle=0): ??? win32clipboard.OpenClipboard(window_handle) ??? if isinstance(format, str): ??????? format = _format_to_number(format) ??? try: ??????? ret = win32clipboard.GetClipboardData(format) ??? except TypeError: ??????? return None ??? finally: ??????? win32clipboard.CloseClipboard() ??? return ret #def check_clipboard_format(format=win32clipboard.CF_TEXT, window_handle=0): def check_clipboard_format(format=win32clipboard.CF_UNICODETEXT, window_handle=0): ??? if isinstance(format, str): ??????? format = _format_to_number(format) ??? win32clipboard.OpenClipboard(window_handle) ??? try: ??????? return win32clipboard.IsClipboardFormatAvailable(format) ??? finally: ??????? win32clipboard.CloseClipboard() def get_clipboard_formats(window_handle=0): ??? format = 0 ??? formats = [] ??? win32clipboard.OpenClipboard(window_handle) ??? standard_formats = {} ??? for n in dir(win32clipboard): ??????? if not n.startswith("CF_"): continue ??????? standard_formats[getattr(win32clipboard, n)] = n[3:] ??? try: ??????? while True: ??????????? format = win32clipboard.EnumClipboardFormats(format) ??????????? if not format: ??????????????? break ??????????? if format in standard_formats: ??????????????? formats.append(standard_formats[format]) ??????????? else: ??????????????? formats.append( win32clipboard.GetClipboardFormatName(format) ) ??? finally: ??????? win32clipboard.CloseClipboard() ??? return formats From i_was_yah00ed at yahoo.com Wed Dec 1 09:17:33 2021 From: i_was_yah00ed at yahoo.com (gw1500) Date: Wed, 1 Dec 2021 09:17:33 -0500 Subject: [python-win32] Clipboard Documentation In-Reply-To: References: <6415224c-0fcf-dada-cbcf-9c2beecf64aa.ref@bellsouth.net> <6415224c-0fcf-dada-cbcf-9c2beecf64aa@bellsouth.net> <8b9df814-aa88-21ae-c82d-6a835b109068@probo.com> <8510f81f-0566-a39c-97ab-689063613bc9@yahoo.com> Message-ID: On 12/1/2021 3:07 AM, Tim Roberts wrote: > On 11/30/21 7:04 AM, gw1500 via python-win32 wrote: > >> >> Thanks for the reply. I read about that but was hoping to use >> pywin32. I can see now the folly of that decision. >> >> I have a working minimal test but am looking for something a bit more >> automated. I bring my app window to the top using pywin32 and a line >> I need is already highlighted. I can ctrl-c from the keyboard and >> pyperclip works just fine. However, since the line is already >> highlighted is there a way to get it without user interaction (ctrl-c)? > > ?I don't know how much trouble you want to go to.? If you can get the > window handle of the text box that has your text, you can send a > WM_COPY message to it.? With the standard controls, that tells it to > do a "copy" operation with the currently selected text. > Hi Tim, Thanks. That was what I wanted to know. From i_was_yah00ed at yahoo.com Wed Dec 1 13:09:13 2021 From: i_was_yah00ed at yahoo.com (gw1500) Date: Wed, 1 Dec 2021 13:09:13 -0500 Subject: [python-win32] Clipboard Documentation In-Reply-To: <346fb926-3087-01b7-9ab0-6df0a2175521@schwertberger.de> References: <6415224c-0fcf-dada-cbcf-9c2beecf64aa.ref@bellsouth.net> <6415224c-0fcf-dada-cbcf-9c2beecf64aa@bellsouth.net> <8b9df814-aa88-21ae-c82d-6a835b109068@probo.com> <8510f81f-0566-a39c-97ab-689063613bc9@yahoo.com> <346fb926-3087-01b7-9ab0-6df0a2175521@schwertberger.de> Message-ID: <95de494d-5b27-2b7d-e460-328f1ba0f621@yahoo.com> Hi Dietmar, Thanks. I lot to it but I'll give it a try. On 12/1/2021 11:33 AM, Dietmar Schwertberger wrote: > I've been using the code below for 20 years now for text copy & paste. > No guarantees, though. > > > Regards, > > Dietmar > > > def copy_to_clipboard(text, window_handle=0): > ??? """copy_to_clipboard(window_handle, text): > ??? copy a string to the clipboard.""" > ??? win32clipboard.OpenClipboard(window_handle) > ??? try: > ??????? win32clipboard.EmptyClipboard() > ??????? if sys.version_info.major==2: > ??????????? is_unicode = isinstance(text, str) > ??????? else: > ??????????? is_unicode = True > ??????? if is_unicode: > win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, text) > ??????? else: > ??????????? win32clipboard.SetClipboardText(text) > ??? finally: > ??????? win32clipboard.CloseClipboard() > > _formats = {} > def _format_to_number(format): > ??? if not format in _formats: > ??????? number = win32clipboard.RegisterClipboardFormat(format) > ??????? _formats[format] = number > ??? return _formats[format] > > #def copy_from_clipboard(format=win32clipboard.CF_TEXT, window_handle=0): > def copy_from_clipboard(format=win32clipboard.CF_UNICODETEXT, > window_handle=0): > ??? win32clipboard.OpenClipboard(window_handle) > ??? if isinstance(format, str): > ??????? format = _format_to_number(format) > ??? try: > ??????? ret = win32clipboard.GetClipboardData(format) > ??? except TypeError: > ??????? return None > ??? finally: > ??????? win32clipboard.CloseClipboard() > ??? return ret > > > > #def check_clipboard_format(format=win32clipboard.CF_TEXT, > window_handle=0): > def check_clipboard_format(format=win32clipboard.CF_UNICODETEXT, > window_handle=0): > ??? if isinstance(format, str): > ??????? format = _format_to_number(format) > ??? win32clipboard.OpenClipboard(window_handle) > ??? try: > ??????? return win32clipboard.IsClipboardFormatAvailable(format) > ??? finally: > ??????? win32clipboard.CloseClipboard() > > > def get_clipboard_formats(window_handle=0): > ??? format = 0 > ??? formats = [] > ??? win32clipboard.OpenClipboard(window_handle) > ??? standard_formats = {} > ??? for n in dir(win32clipboard): > ??????? if not n.startswith("CF_"): continue > ??????? standard_formats[getattr(win32clipboard, n)] = n[3:] > ??? try: > ??????? while True: > ??????????? format = win32clipboard.EnumClipboardFormats(format) > ??????????? if not format: > ??????????????? break > ??????????? if format in standard_formats: > ??????????????? formats.append(standard_formats[format]) > ??????????? else: > ??????????????? formats.append( > win32clipboard.GetClipboardFormatName(format) ) > ??? finally: > ??????? win32clipboard.CloseClipboard() > ??? return formats > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 From drmoisan at gmail.com Tue Dec 7 21:49:08 2021 From: drmoisan at gmail.com (Dan Moisan) Date: Tue, 7 Dec 2021 18:49:08 -0800 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in Message-ID: I apologize in advance for the basic question, but I have spent about 40 hours researching how to make the demo "outlookAddin.py" load on my Outlook 2016 32 bit application. I am running Python version 3.7 and I can successfully run the outlookAddin.py script from PyCharm. But then when I open outlook, I always receive the message "... not loaded. a runtime error occurred during the loading of the com add-in". I am sure that I missing a very basic step to make this run, but I can't seem to find anything online. Do I need to do something to compile the outlookAddin.py script before or after I run it? Or should the add-in load after it is registered? I'm so sorry for such a basic question. Thank you! Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Wed Dec 8 08:48:24 2021 From: vernondcole at gmail.com (Vernon D. Cole) Date: Wed, 8 Dec 2021 06:48:24 -0700 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in In-Reply-To: References: Message-ID: Most likely, you are running a 64 bit version of Python. Due to Windows restrictions, only 32 bit programs can talk to each other. If you download and install a 32 bit version of Python, you may find success. PyCharm and Windows will happily allow multiple versions of Python to work alongside each other. Select your Python version under File --> Settings --> Project --> Python Interpreter On Tue, Dec 7, 2021 at 8:30 PM Dan Moisan wrote: > I apologize in advance for the basic question, but I have spent about 40 > hours researching how to make the demo "outlookAddin.py" load on my Outlook > 2016 32 bit application. I am running Python version 3.7 and I can > successfully run the outlookAddin.py script from PyCharm. But then when I > open outlook, I always receive the message "... not loaded. a runtime error > occurred during the loading of the com add-in". > > I am sure that I missing a very basic step to make this run, but I can't > seem to find anything online. Do I need to do something to compile the > outlookAddin.py script before or after I run it? Or should the add-in load > after it is registered? I'm so sorry for such a basic question. > > Thank you! > > Dan > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Dec 8 15:42:47 2021 From: timr at probo.com (Tim Roberts) Date: Wed, 8 Dec 2021 12:42:47 -0800 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in In-Reply-To: References: Message-ID: <8162fefe-7044-686a-972d-9651bf7235ed@probo.com> Vernon D. Cole wrote: > Most likely, you are running a 64? bit version of Python. > Due to Windows restrictions, only 32 bit programs can talk to each other. That comment demands clarification, because as stated it is quite misleading. The issue here is that a 32-bit application can only load 32-bit DLLs.? Outlook 2016 is a 32-bit application, so when it as a COM client tries to load an in-process COM server (that is, his add-in), the COM server DLL must also be 32-bit. There are many, many ways that 32-bit and 64-bit programs can talk to each other.? This is a very specific instance. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3389 bytes Desc: S/MIME Cryptographic Signature URL: From steven at manross.net Wed Dec 8 16:36:11 2021 From: steven at manross.net (Steven Manross) Date: Wed, 8 Dec 2021 21:36:11 +0000 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in In-Reply-To: <8162fefe-7044-686a-972d-9651bf7235ed@probo.com> References: <8162fefe-7044-686a-972d-9651bf7235ed@probo.com> Message-ID: Correct me if I am wrong... but Office 2010+ comes in 64-bit and 32-bit versions. I know that 2019 definitely does. Providing he matches his Python architecture (32 or 64) to his Office application architecture (32 or 64), it should work unless that code has issues working in 64-bit mode? I haven?t tried this myself in this particular case, as I've always installed 32-bit Office apps. As well, I just tried to run the addin code with my 64-bit python and it told me " Library not registered". C:\scripts>python outlookaddin.py Traceback (most recent call last): File "outlookaddin.py", line 38, in gencache.EnsureModule('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 1, bForDemand=True) # Office 9 File "C:\Python36\lib\site-packages\win32com\client\gencache.py", line 605, in EnsureModule bBuildHidden=bBuildHidden, File "C:\Python36\lib\site-packages\win32com\client\gencache.py", line 319, in MakeModuleForTypelib bBuildHidden=bBuildHidden, File "C:\Python36\lib\site-packages\win32com\client\makepy.py", line 257, in GenerateFromTypeLibSpec tlb = pythoncom.LoadRegTypeLib(typelibCLSID, major, minor, lcid) pywintypes.com_error: (-2147319779, 'Library not registered.', None, None) Its possible that my Office 2019 install doesn?t have the correct components or APPIDs or CLSIDs installed (even if I matched the python and office architectures) as I searched for them and couldn?t find them in the native x64 and x86 registry subkeys: * HKEY_CLASSES_ROOT * HKLM\Software\Classes * OR HKLM\Software\Wow6432Node\Classes These 2 IDs (Maybe only there in older office versions? Not Sure): {00062FFF-0000-0000-C000-000000000046} {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52} The Library Not registered is what I would expect if you were running into a 64-bit python and 32-bit application (or vice versa) problem as the script just wouldn't find the needed library. I see this a lot with ODBC access to MS SQL Server, Sybase, et al (not having the correct architecture's drivers installed to perform the operation I am expecting to work) in VBScript, Perl and Python. HTH Steven -----Original Message----- From: python-win32 On Behalf Of Tim Roberts Sent: Wednesday, December 08, 2021 1:43 PM To: python-win32 Subject: Re: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in Vernon D. Cole wrote: > Most likely, you are running a 64? bit version of Python. > Due to Windows restrictions, only 32 bit programs can talk to each other. That comment demands clarification, because as stated it is quite misleading. The issue here is that a 32-bit application can only load 32-bit DLLs. Outlook 2016 is a 32-bit application, so when it as a COM client tries to load an in-process COM server (that is, his add-in), the COM server DLL must also be 32-bit. There are many, many ways that 32-bit and 64-bit programs can talk to each other.? This is a very specific instance. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From vernondcole at gmail.com Wed Dec 8 17:02:02 2021 From: vernondcole at gmail.com (Vernon D. Cole) Date: Wed, 8 Dec 2021 15:02:02 -0700 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in In-Reply-To: <8162fefe-7044-686a-972d-9651bf7235ed@probo.com> References: <8162fefe-7044-686a-972d-9651bf7235ed@probo.com> Message-ID: Thanks, Tim. Your depth of knowledge is appreciated. I have never understood the "magic" which happens when you make a COM call. Now it all makes sense why 32 and 64 bit COM are mutually incompatible. On Wed, Dec 8, 2021 at 1:52 PM Tim Roberts wrote: > Vernon D. Cole wrote: > > Most likely, you are running a 64 bit version of Python. > > Due to Windows restrictions, only 32 bit programs can talk to each other. > > That comment demands clarification, because as stated it is quite > misleading. > > The issue here is that a 32-bit application can only load 32-bit DLLs. > Outlook 2016 is a 32-bit application, so when it as a COM client tries > to load an in-process COM server (that is, his add-in), the COM server > DLL must also be 32-bit. > > There are many, many ways that 32-bit and 64-bit programs can talk to > each other. This is a very specific instance. > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed Dec 8 19:32:44 2021 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 9 Dec 2021 11:32:44 +1100 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in In-Reply-To: References: Message-ID: <9d22aebd-6c14-d69a-0462-524e9e4b9b75@gmail.com> Another possibility for the failure is the environment office is running under (which broadly speaking can be described as the PATH). Back in the day, it was very common for Python and pywin32 to end up sticking stuff in the system32 directory, then things like COM would work in almost every context, as the system directory was (almost) always on the path. However, these days that's far less likely to be true - so the problem might be as simple as the fact that pythonXX.dll and pythoncomXX.dll can't be located when office is running, although can be in your pycharm environment. Ensuring the directory with these files is on the PATH for office is the generic advice, but it's difficult to give more specific advice without knowing more about your specific environment. Cheers, Mark On 8/12/2021 1:49 pm, Dan Moisan wrote: > I apologize in advance for the basic question, but I have spent about 40 > hours researching how to make the demo "outlookAddin.py" load on my > Outlook 2016 32 bit application. I am running Python version 3.7 and I > can successfully run the outlookAddin.py script from PyCharm. But then > when I open outlook, I always receive the message "...?not loaded. a > runtime error occurred during the loading of the com add-in". > > I am sure that I missing a very basic step to make this run, but I can't > seem to find anything online. Do I need to do something to compile the > outlookAddin.py script before or after I run it? Or should the add-in > load after it is registered? I'm so sorry for such a basic question. > > Thank you! > > Dan > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 From drmoisan at gmail.com Wed Dec 8 19:34:59 2021 From: drmoisan at gmail.com (Dan Moisan) Date: Wed, 8 Dec 2021 16:34:59 -0800 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in In-Reply-To: <9d22aebd-6c14-d69a-0462-524e9e4b9b75@gmail.com> References: <9d22aebd-6c14-d69a-0462-524e9e4b9b75@gmail.com> Message-ID: You all are brilliant for responding. Thank you for being so kind! I will try these fixes and get back to you. Thank you so much!!! On Wed, Dec 8, 2021 at 4:32 PM Mark Hammond wrote: > Another possibility for the failure is the environment office is running > under (which broadly speaking can be described as the PATH). > > Back in the day, it was very common for Python and pywin32 to end up > sticking stuff in the system32 directory, then things like COM would > work in almost every context, as the system directory was (almost) > always on the path. > > However, these days that's far less likely to be true - so the problem > might be as simple as the fact that pythonXX.dll and pythoncomXX.dll > can't be located when office is running, although can be in your pycharm > environment. > > Ensuring the directory with these files is on the PATH for office is the > generic advice, but it's difficult to give more specific advice without > knowing more about your specific environment. > > Cheers, > > Mark > > On 8/12/2021 1:49 pm, Dan Moisan wrote: > > I apologize in advance for the basic question, but I have spent about 40 > > hours researching how to make the demo "outlookAddin.py" load on my > > Outlook 2016 32 bit application. I am running Python version 3.7 and I > > can successfully run the outlookAddin.py script from PyCharm. But then > > when I open outlook, I always receive the message "... not loaded. a > > runtime error occurred during the loading of the com add-in". > > > > I am sure that I missing a very basic step to make this run, but I can't > > seem to find anything online. Do I need to do something to compile the > > outlookAddin.py script before or after I run it? Or should the add-in > > load after it is registered? I'm so sorry for such a basic question. > > > > Thank you! > > > > Dan > > > > _______________________________________________ > > python-win32 mailing list > > python-win32 at python.org > > https://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Dec 9 13:27:04 2021 From: timr at probo.com (Tim Roberts) Date: Thu, 9 Dec 2021 10:27:04 -0800 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in In-Reply-To: References: <8162fefe-7044-686a-972d-9651bf7235ed@probo.com> Message-ID: Steven Manross wrote: > Correct me if I am wrong... but Office 2010+ comes in 64-bit and 32-bit versions. I know that 2019 definitely does. Both are available, but until Office 2019 the 32-bit version was the default, so that's what virtually everyone has. > Providing he matches his Python architecture (32 or 64) to his Office application architecture (32 or 64), it should work unless that code has issues working in 64-bit mode? I haven?t tried this myself in this particular case, as I've always installed 32-bit Office apps. Right. > Its possible that my Office 2019 install doesn?t have the correct components or APPIDs or CLSIDs installed (even if I matched the python and office architectures) as I searched for them and couldn?t find them in the native x64 and x86 registry subkeys: > > * HKEY_CLASSES_ROOT > * HKLM\Software\Classes > * OR HKLM\Software\Wow6432Node\Classes Is this the desktop versions or the Office 365 versions?? There are differences. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3389 bytes Desc: S/MIME Cryptographic Signature URL: From steven at manross.net Thu Dec 9 14:01:16 2021 From: steven at manross.net (Steven Manross) Date: Thu, 9 Dec 2021 19:01:16 +0000 Subject: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in In-Reply-To: References: <8162fefe-7044-686a-972d-9651bf7235ed@probo.com> Message-ID: <5b601d22080242cdb5fc0327893d8cb3@manross.net> Thanks for verifying! Mine is a Desktop version... not 365 (installed with Product Key not subscription as part of Office Professional Plus 2019) Steven -----Original Message----- From: python-win32 On Behalf Of Tim Roberts Sent: Thursday, December 09, 2021 11:27 AM To: python-win32 Subject: Re: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in Steven Manross wrote: > Correct me if I am wrong... but Office 2010+ comes in 64-bit and 32-bit versions. I know that 2019 definitely does. Both are available, but until Office 2019 the 32-bit version was the default, so that's what virtually everyone has. > Providing he matches his Python architecture (32 or 64) to his Office application architecture (32 or 64), it should work unless that code has issues working in 64-bit mode? I haven?t tried this myself in this particular case, as I've always installed 32-bit Office apps. Right. > Its possible that my Office 2019 install doesn?t have the correct components or APPIDs or CLSIDs installed (even if I matched the python and office architectures) as I searched for them and couldn?t find them in the native x64 and x86 registry subkeys: > > * HKEY_CLASSES_ROOT > * HKLM\Software\Classes > * OR HKLM\Software\Wow6432Node\Classes Is this the desktop versions or the Office 365 versions?? There are differences. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Tamara.Abugharbieh at Realsoft-me.com Sun Dec 12 03:32:01 2021 From: Tamara.Abugharbieh at Realsoft-me.com (Tamara Abugharbieh) Date: Sun, 12 Dec 2021 08:32:01 +0000 Subject: [python-win32] pywin can not access excel file Message-ID: Hi, We are using winpy32 to automate excel applications using python. The python script will be used by users with no administrator privileges, and in this case, we are getting the following error: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', \"Microsoft Excel cannot access the file 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx'. There are several possible reasons: The file name or path does not exist. The file is being used by another program. The workbook you are trying to save has the same name as a currently open workbook.\", 'xlmain11.chm', 0, -2146827284) Things to note: 1. The file does exist 2. The file is not being used by another program 3. The path is correct 4. The python script is being successfully used by users with administrative privileges Please find bellow the method I am using to open the excel file: import win32com.client as w3c filename = 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx' ExcelApp = w3c.DispatchEx("Excel.Application") ExcelApp.Visible = False ExcelApp.DisplayAlerts = False wb = ExcelApp.Workbooks.Open("{0}".format(fileName)) Appreciate your help. Best, Tamara -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at manross.net Sun Dec 12 20:00:21 2021 From: steven at manross.net (Steven Manross) Date: Mon, 13 Dec 2021 01:00:21 +0000 Subject: [python-win32] pywin can not access excel file In-Reply-To: References: Message-ID: <46edcbf8dcd046cba128e862349d44b6@manross.net> Is this a typo on the email or is your production code really referencing filename and fileName? You need to reference the variable name using the same casing in both places (if this is not a typo in your email example). P.S. I don't think you need the 4 backslashes.. 2 usually does the trick, but there's nothing from stopping it from working using 4 backslashes. import win32com.client as w3c # lowercase filename = 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx' ExcelApp = w3c.DispatchEx("Excel.Application") ExcelApp.Visible = False ExcelApp.DisplayAlerts = False # mixed case wb = ExcelApp.Workbooks.Open("{0}".format(fileName)) From: python-win32 On Behalf Of Tamara Abugharbieh Sent: Sunday, December 12, 2021 1:32 AM To: python-win32 at python.org Subject: [python-win32] pywin can not access excel file Hi, We are using winpy32 to automate excel applications using python. The python script will be used by users with no administrator privileges, and in this case, we are getting the following error: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', \"Microsoft Excel cannot access the file 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx'. There are several possible reasons: The file name or path does not exist. The file is being used by another program. The workbook you are trying to save has the same name as a currently open workbook.\", 'xlmain11.chm', 0, -2146827284) Things to note: 1. The file does exist 2. The file is not being used by another program 3. The path is correct 4. The python script is being successfully used by users with administrative privileges Please find bellow the method I am using to open the excel file: import win32com.client as w3c filename = 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx' ExcelApp = w3c.DispatchEx("Excel.Application") ExcelApp.Visible = False ExcelApp.DisplayAlerts = False wb = ExcelApp.Workbooks.Open("{0}".format(fileName)) Appreciate your help. Best, Tamara -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at manross.net Sun Dec 12 20:46:21 2021 From: steven at manross.net (Steven Manross) Date: Mon, 13 Dec 2021 01:46:21 +0000 Subject: [python-win32] pywin can not access excel file In-Reply-To: <46edcbf8dcd046cba128e862349d44b6@manross.net> References: <46edcbf8dcd046cba128e862349d44b6@manross.net> Message-ID: P.S. I also just validated that a non-admin could run the code in ipython with a test xlsx, and open the workbook, navigate to a worksheet, and then read a value in A1 that I put the words "this is a test" in. * Is User Account Control (UAC) enabled on the PC we are troubleshooting with? That could be causing issues and you may need to troubleshoot that. * Does the non-admin have NTFS permissions to the Excel workbook you are working with (my test was just c:\\scripts\\test.xlsx)? (Can the non-admin browse to that file and double click it to open it - just as a test?) * What OS is the PC that we are trying to troubleshoot (W11, W10, W7, W8? Or possibly terminal services on a Server OS?) My test was on W10 x64 build 20H2 * What version of pywin32 are you running and what version of python are we troubleshooting? Im running Python 3.6 my pywin32 version: C:\python36>pip freeze| findstr /c:pywin32 WARNING: Ignoring invalid distribution -ffi (c:\python36\lib\site-packages) pywin32==302 pywin32-ctypes==0.1.2 My guess is that this is more an environmental issue than a python problem, but the version info might help in diagnosing this further. # my test code import win32com.client as w3c filename = 'C:\\\\scripts\\\\this.xlsx' ExcelApp = w3c.DispatchEx("Excel.Application") ExcelApp.Visible = False ExcelApp.DisplayAlerts = False wb = ExcelApp.Workbooks.Open("{0}".format(filename)) worksheet = wb.Worksheets[0] worksheet.Range("A1").Value # Ipython output: In [5]: worksheet.Range("A1").Value Out[5]: 'this is a test' P.S. Im also a fan of F-strings... wb = ExcelApp.Workbooks.Open(f"{filename}") OR more simply wb = ExcelApp.Workbooks.Open(filename) HTH Steven From: python-win32 On Behalf Of Steven Manross Sent: Sunday, December 12, 2021 6:00 PM To: Tamara Abugharbieh ; python-win32 at python.org Subject: Re: [python-win32] pywin can not access excel file Is this a typo on the email or is your production code really referencing filename and fileName? You need to reference the variable name using the same casing in both places (if this is not a typo in your email example). P.S. I don't think you need the 4 backslashes.. 2 usually does the trick, but there's nothing from stopping it from working using 4 backslashes. import win32com.client as w3c # lowercase filename = 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx' ExcelApp = w3c.DispatchEx("Excel.Application") ExcelApp.Visible = False ExcelApp.DisplayAlerts = False # mixed case wb = ExcelApp.Workbooks.Open("{0}".format(fileName)) From: python-win32 On Behalf Of Tamara Abugharbieh Sent: Sunday, December 12, 2021 1:32 AM To: python-win32 at python.org Subject: [python-win32] pywin can not access excel file Hi, We are using winpy32 to automate excel applications using python. The python script will be used by users with no administrator privileges, and in this case, we are getting the following error: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', \"Microsoft Excel cannot access the file 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx'. There are several possible reasons: The file name or path does not exist. The file is being used by another program. The workbook you are trying to save has the same name as a currently open workbook.\", 'xlmain11.chm', 0, -2146827284) Things to note: 1. The file does exist 2. The file is not being used by another program 3. The path is correct 4. The python script is being successfully used by users with administrative privileges Please find bellow the method I am using to open the excel file: import win32com.client as w3c filename = 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx' ExcelApp = w3c.DispatchEx("Excel.Application") ExcelApp.Visible = False ExcelApp.DisplayAlerts = False wb = ExcelApp.Workbooks.Open("{0}".format(fileName)) Appreciate your help. Best, Tamara -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Dec 13 00:37:08 2021 From: timr at probo.com (Tim Roberts) Date: Sun, 12 Dec 2021 21:37:08 -0800 Subject: [python-win32] pywin can not access excel file In-Reply-To: References: Message-ID: On 12/12/21 12:32 AM, Tamara Abugharbieh wrote: > We are using winpy32 to automate excel applications using python. The > python script will be used by users with no administrator privileges, > and in this case, we are getting the following error: > > pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, > 'Microsoft Excel', \"Microsoft Excel cannot access the file > 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx'. > There are several possible reasons: The file name or path does not > exist. The file is being used by another program. The workbook you are > trying to save has the same name as a currently open workbook.\", > 'xlmain11.chm', 0, -2146827284) > Have you checked the permissions (with Explorer or with icacls) to see if the files are readable by "All Users"?? Can one of those users open the file from Excel, without using your script? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wlfraed at ix.netcom.com Mon Dec 13 07:34:18 2021 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Mon, 13 Dec 2021 07:34:18 -0500 Subject: [python-win32] pywin can not access excel file References: Message-ID: On Sun, 12 Dec 2021 08:32:01 +0000, Tamara Abugharbieh declaimed the following: >filename = 'C:\\\\App\\\\Backend\\\\public\\\\MSB_2021\\\\11\\\\SYB_10_7_V1.xlsx' > That looks like an awful lot of \s. Unless you are passing that string to a command line/shell, the Windows API itself is happy with single /s (which avoids any problem of needing to escape \s to avoid some combos being treated as special characters). >ExcelApp = w3c.DispatchEx("Excel.Application") >ExcelApp.Visible = False >ExcelApp.DisplayAlerts = False >wb = ExcelApp.Workbooks.Open("{0}".format(fileName)) As has been mentioned, filename and fileName aren't the same entity (though the error message does reference the string you provided, so something is not the code you actually ran). -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ From mhammond at skippinet.com.au Sun Dec 19 21:16:44 2021 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 20 Dec 2021 13:16:44 +1100 Subject: [python-win32] [ANN] pywin32 build 303 released Message-ID: Hi all, I'm happy to announce the release of pywin32 build 303. There are a small number of changes in this release, but maybe virtualenv will work better! 3.11 gets support, but no .exe installers for 32-bit 3.10+ due to Python dropping support for bdist_wininst. Downloads are available at: https://github.com/mhammond/pywin32/releases/tag/b303 and via pypi. For initial support (eg, to ask questions about the release etc), please contact this mailing-list (python-win32 at python.org). If you want to report a bug, please do so at https://github.com/mhammond/pywin32/issues As always, thanks to everyone who contributed to this release, both in terms of code and reporting bugs - there were a number of new contributors which is great to see, Cheers, Mark. Changes: Since build 302: ---------------- * Tweaks to how DLLs are loaded and our installation found, which should improve virtualenv support and version mismatch issues (#1787, #1794) * Fixed a bug where `win32clipboard.GetClipboardData()` may have returned extra data. * Binary installers for 32-bit 3.10+ are no longer released (#1805)