title: Convert Microsoft Word document to PDF using Python
body: <p>I have tons of Word and Excel files. I want to convert many Word files in folders by sub folders to PDF, and I try following code.</p>
  
  <p>This code is not active (I mean there aren't Word convert to PDF) although no error.</p>
  
  <p><a href="https://i.stack.imgur.com/xbyMg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xbyMg.png" alt="Enter image description here"></a></p>
  
  <p>What could be the problem? Is there another solution?</p>
  
  <p>This is my code:</p>
  
  <pre><code>import os
  from win32com import client
  path = 'D:\programing\test'
  word_file_names = []
  word = client.DispatchEx("Word.Application")
  for dirpath, dirnames, filenames in os.walk(path):
      print (dirpath)
      for f in filenames:
          if f.lower().endswith(".docx") and re.search('Addendum', f):
              new_name = f.replace(".docx", r".pdf")
              in_file = word_file_names.append(dirpath + "\\" + f)
              new_file = word_file_names.append(dirpath + "\\" + new_name)
              doc = word.Documents.Open(in_file)
              doc.SaveAs(new_file, FileFormat = 17)
              doc.Close()
          if f.lower().endswith(".doc") and re.search('Addendum', f):
              new_name = f.replace(".doc", r".pdf")
              in_file = word_file_names.append(dirpath + "\\" + f)
              new_file = word_file_names.append(dirpath + "\\" + new_name)
              doc = word.Documents.Open(in_file)
              doc.SaveAs(new_file, FileFormat = 17)
              doc.Close()
      word.Quit()
  </code></pre>