?
Solved

Setting/Changing File Custom Properties using VBScript

Posted on 2004-09-17
5
Medium Priority
?
725 Views
Last Modified: 2012-06-21
Hi

I am currently working on a (.vbs) script to migrate files from an old version to a new one. I want to set Custom File Properties for some of the files using the script. I know that Visual Basic has a couple of ways of doing this. But can someone tell me if they (or any other method) work with VBScript

Thanks

Prasad
0
Comment
Question by:PrasadViswanathan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:Michael_D
ID: 12086706
What "Custom Properties" do you mean?

Here is sample from MSDN shows how to set file attributes? Is it what you want?

Sub SetClearArchiveBit(filespec)
    Dim fs, f, r
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(fs.GetFileName(filespec))
    If f.attributes and 32 Then
        r = MsgBox("The Archive bit is set, do you want to clear it?", vbYesNo, "Set/Clear Archive Bit")
        If r = vbYes Then
            f.attributes = f.attributes - 32
            MsgBox "Archive bit is cleared."
        Else
            MsgBox "Archive bit remains set."
        End If
    Else
        r = MsgBox("The Archive bit is not set. Do you want to set it?", vbYesNo, "Set/Clear Archive Bit")
        If r = vbYes Then
            f.attributes = f.attributes + 32
            MsgBox "Archive bit is set."
        Else
            MsgBox "Archive bit remains clear."
        End If
    End If
End Sub

0
 
LVL 13

Expert Comment

by:Michael_D
ID: 12086739
you can look here to see which file properties available using FSO

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjfile.asp
0
 
LVL 76

Accepted Solution

by:
David Lee earned 750 total points
ID: 12087836
Custom File Properties makes me think you're talking about document properties instead of file properties.  If so, then you can use DSO to get to the document properties of an Office document.  Here's a link to where you can get the DSO object.

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q224/3/51.asp&NoWebContent=1

Here's a link to another EE question that contains a DSO example: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20794252.html

Look for the post:

Comment from g0rath
Date: 11/11/2003 09:46AM EST
0
 

Author Comment

by:PrasadViswanathan
ID: 12107844
Thank you all for your comments. The file "Custom Properties" I was referring to is the "Custom Properties" TAB that you get when you right click the file and go to properties. I will try the DSO and let you know. Thanks again for the quick replies.

Prasad
0
 

Author Comment

by:PrasadViswanathan
ID: 12125478
The DSO example didn't exactly work as given on that site, but it helped a great deal to point me in the right direction. This is the code I used that worked.

'***************************************************************
'Set the Document Property Reader and read properties of a file.
'***************************************************************

sFile = "Test File.xls"
Set oFilePropReader = CreateObject("DSOleFile.PropertyReader")
Set oDocProp = oFilePropReader.GetDocumentProperties(sFile)

'***************************************************************
'Set the Custom Properties.
'***************************************************************
oDocProp.CustomProperties.Add "Source_Name", False
oDocProp.CustomProperties.Item("Source_Name").Value = "somefilename.xls"

But I'll accept that answer :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question