Skip to content

Instantly share code, notes, and snippets.

@AJP4
Last active March 25, 2018 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AJP4/e17b7cc75d97ea105c6161065fee1cd6 to your computer and use it in GitHub Desktop.
Save AJP4/e17b7cc75d97ea105c6161065fee1cd6 to your computer and use it in GitHub Desktop.
Generate MS Office Constants
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# How to Generate MS Office Constants for Use with Win32Com"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Change the object library reference depending on your version of MS Office"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing Microsoft Office 16.0 Object Library\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building definitions from type library...\n",
"Generating...\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing Microsoft Excel 16.0 Object Library\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building definitions from type library...\n",
"Generating...\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing Microsoft PowerPoint 16.0 Object Library\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building definitions from type library...\n",
"Generating...\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing Microsoft Word 16.0 Object Library\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Building definitions from type library...\n",
"Generating...\n"
]
}
],
"source": [
"# to generate all your MS Office constants\n",
"# create tuples linking object library reference to file name you want\n",
"MSO= (\"Microsoft Office 16.0 Object Library\",\"./MSOconstants/MSO.py\")\n",
"MSXLS=(\"Microsoft Excel 16.0 Object Library\",\"./MSOconstants/MSXLS.py\")\n",
"MSPPT=(\"Microsoft PowerPoint 16.0 Object Library\",\"./MSOconstants/MSPPT.py\")\n",
"MSWORD=(\"Microsoft Word 16.0 Object Library\",\"./MSOconstants/MSWORD.py\")\n",
"\n",
"# put these tuples in list for ease of iterating over\n",
"constants=[MSO, MSXLS, MSPPT, MSWORD]\n",
"\n",
"\n",
"import sys \n",
"from win32com.client import makepy\n",
"for officeApp in constants:\n",
" print(\"Processing \",officeApp[0])\n",
" sys.argv = ['', \"-o\", officeApp[1], officeApp[0]]\n",
" makepy.main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (jupyterLab)",
"language": "python",
"name": "jupyterlab"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment