Solved

Setting/Changing File Custom Properties using VBScript

Posted on 2004-09-17
5
640 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
  • 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 250 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now