Skip to content

Instantly share code, notes, and snippets.

@nitram2342
Created July 16, 2017 19:41
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 nitram2342/7356aab478987d03a463da44d6261dfd to your computer and use it in GitHub Desktop.
Save nitram2342/7356aab478987d03a463da44d6261dfd to your computer and use it in GitHub Desktop.
Update VBA code in Word templates programatically
#!/bin/sh
#
# Helper script to extract a VBA code blob from a Microsoft Word template
# and update the VBA code blobs in other Word templates.
#
# Author: Martin Schobert <martin@weltregierung.de>
#
SRC=$1
DST=$2
# check if files exists
if [ ! -f $SRC ] ; then
echo file "$SRC" does not exist
exit
fi
if [ ! -f $DST ] ; then
echo file "$DST" does not exist
exit
fi
# extract vba code from source archive
unzip -j $SRC word/vbaProject.bin -d .
# delete vba code in destination archive
zip -d $DST word/vbaProject.bin
# add new vba code to destination archive
zip $DST vbaProject.bin
# rename file, respectivley change the path
printf "@ vbaProject.bin\n@=word/vbaProject.bin" | zipnote -w $DST
# show archive content
unzip -l $DST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment