Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.NET - Edit file property "Company" etc?
    primarykey
    data
    text
    <p>I was wondering how I can set a file's properties? I'm talking about the fields, author, company etc. I found a way of doing it through Word's builtin properties. But it's a little buggy. So I was wondering if it's possible to do that in other ways?</p> <p>I have this code that works for all Word document files except *.doc format it seems. This is the code I have so far, one text box and one button. The button runs findDocLoop()</p> <pre><code> Dim oWord As Word.Application Dim oDoc As Word.Document Dim oBuiltInProps As Object Public Sub findDocLoop() Dim strRootPath As String strRootPath = txtBoxRootpath.Text Dim di As New IO.DirectoryInfo(strRootPath) Dim aryFi As IO.FileInfo() = di.GetFiles("*.doc") Dim aryFi2 As IO.FileInfo() = di.GetFiles("*.dot") Dim aryFi3 As IO.FileInfo() = di.GetFiles("*.doc*") Dim fi As IO.FileInfo For Each fi In aryFi If Not fi.FullName.Contains("~$") Then RunRenameProcess(txtBoxRootpath.Text &amp; "\" &amp; fi.ToString) End If Next For Each fi In aryFi2 If Not fi.FullName.Contains("~$") Then RunRenameProcess(txtBoxRootpath.Text &amp; "\" &amp; fi.ToString) End If Next For Each fi In aryFi3 If Not fi.FullName.Contains("~$") Then RunRenameProcess(txtBoxRootpath.Text &amp; "\" &amp; fi.ToString) End If Next oDoc = Nothing lblDone.Text = "Finished" End Sub Public Function FileInUse(ByVal sFile As String) As Boolean Dim thisFileInUse As Boolean = False If System.IO.File.Exists(sFile) Then Try Using f As New IO.FileStream(sFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None) thisFileInUse = False End Using Catch thisFileInUse = True writeToLog(sFile) End Try End If Return thisFileInUse End Function Public Sub writeToLog(ByVal strFile As String) Dim sContents As String sContents = strFile &amp; " - " &amp; DateTime.Now.ToLongTimeString SaveTextToFile(sContents, Directory.GetCurrentDirectory &amp; "\errorlog.txt") End Sub Private Sub RunRenameProcess(ByVal strFile) If FileInUse(strFile) = False Then 'Create instance of Word and make it visible 'On Error Resume Next oDoc = oWord.Documents.Open(strFile) 'Get the properties collection in file oBuiltInProps = oDoc.BuiltInDocumentProperties 'Set the value of the properties oBuiltInProps.Item("Company").Value = txtBoxCompany.Text ' AT THIS POINT, THE PROPERTY IS ACTUALLY SET (IF I CHECK IN WORD) oDoc.Save() ' AT THIS POINT, THE PROPERTY IS RESET TO THE DEFAULT WORD COMPANY VALUE(DOMAIN) oDoc.Close() End If End Sub </code></pre> <p>I know it can probably be done better, but I'm kinda in a hurry. I just noticed when I set a break point right after the code sets the value of the property. I set Word to be open, got in there and checked the property value. And it was actually set!. But after the save phaze, it seems to be lost. Or "reset" to some Office defaults. Which is my company name.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload