I would like to know the sensitivity label of my current Word file, change it with a new value and save my file
I start by opening a Word file
# Opening a MS Word file in pywin32
from win32com.client import Dispatch
myWord = Dispatch('Word.Application')
myWord.Visible = 1
myWord.Documents.Open("C:/./TEMP.docx") # open file
# SetLabel and GetLabel
print(myWord.ActiveDocument.SensitivityLabel)
print(myWord.ActiveDocument.SensitivityLabel.SetLabel)
print(myWord.ActiveDocument.SensitivityLabel.GetLabel())
# Create label info
myLabelInfoNew = myWord.ActiveDocument.SensitivityLabel.CreateLabelInfo()
# Close Word Application
myWord.ActiveDocument.SaveAs("C:/./TEMP2.docx")
myWord.Quit()
How can I fix it?
Thank you for your help
This is the code I use with to apply sensitivity to .xlsx documents. Create a .docx file for each sensitivity type your company uses. Run the first function on each sensitivity type document you have to get your company's Sensitivity IDs per type. You then update the dictionary in the second function with the appropriate IDs. For this to work on .docx files you will need to change a few things in the code below. Please see the items below for changes.
Update below for docx