title: Using python to autofill a word.docx from excel file
body: <p>I'm about halfway through Automate the Boring Stuff with Python textbook and video tutorials, however I have a big project at work where I need to autopopulate 60 Chemical Purchase Review documents that we can't seem to find. Rather than fill them out individually, I'd like to use what I've learned so far. I've had to jump ahead in chapters, but I can't seem to figure out how to get past the last line of code.
  Basically, I have an excel spreadsheet with four columns of information I need to be input into certain areas on the word document form template.
  I have "AAAA, BBBB..." in the word doc as a something to be found and replaced.</p>
  
  <pre><code>import openpyxl,os,docx,re
  
  os.chdir(r'C:\Users\MYUSERNAME\OneDrive\Documents\Programming\ChemInv')
  
  wb = openpyxl.load_workbook('cheminv.xlsx')
  sheet = wb.get_sheet_by_name('Sheet1')
  doc = docx.Document('ChemPurchaseForm_.docx')
  fillObj = ('AAAA','BBBB','CCCC','DDDD')
  
  for a in range(1,61):
      for b in range(1,5):
          fill = sheet.cell(row=a,column=b).value
          for x in range(len(fillObj)):
              inputRegex = re.compile(fillObj[x])
              inputRegex.sub(fill,doc)
  
          doc.save('ChemPurcaseForm_' + fill + '.docx')   
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <pre><code>Traceback (most recent call last):
      File "C:/Users/MYUSERNAME/OneDrive/Documents/Programming/ChemInv/autofill.py", line 
  15, in &lt;module&gt;
      inputRegex.sub(fill,doc)
  TypeError: expected string or bytes-like object
  </code></pre>
  
  <p>I'm assuming that either the "fill" variable or "doc" variable are not binary or string values?</p>
  
  <p>Thank you in advance for help!</p>