Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Setting/Changing File Custom Properties using VBScript

Posted on 2004-09-17
5
Medium Priority
?
758 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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

636 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