PC Review


Reply
Thread Tools Rate Thread

creating filename

 
 
Andrew
Guest
Posts: n/a
 
      1st Apr 2008
How can I create a file name based on the entries in the "properties" section
of a document?
--
agibson
 
Reply With Quote
 
 
 
 
Ivyleaf
Guest
Posts: n/a
 
      1st Apr 2008
Hi Andrew,

ThisWorkbook.BuiltinDocumentProperties(PropertyName) will read the
property from the file... use CustomDocumentProperties for a custom
property, but be aware that this will return an error if the property
doesn't exist.

Once you have the properties read, just join 'em up however you want
to make the filename. I would advise though that you sick in some well
thought out error handling code to cater for:

Properties not existing
Properties being null length (if it hasn't been filled out for some
reason)
Properties containing characters that will be invalid in a file
name... eg. you might want to do a Replace(NewFileName,"/","-") or
something similar to ensure the save won't fail.

Hope this helps.

Cheers,
Ivan.

On Apr 1, 12:00*pm, Andrew <and...@discussions.microsoft.com> wrote:
> How can I create a file name based on the entries in the "properties" section
> of a document?
> --
> agibson


 
Reply With Quote
 
Ivyleaf
Guest
Posts: n/a
 
      1st Apr 2008
This code from Chip Pearson will help you with the property names:

Sub Properties()
Dim N As Long
On Error Resume Next
With ThisWorkbook.BuiltinDocumentProperties
For N = 1 To .Count
Cells(N, 1).Value = .Item(N).Name
Cells(N, 2).Value = .Item(N).Value
If Err.Number <> 0 Then
Cells(N, 2).Value = CVErr(xlErrNA)
Err.Clear
End If
Next N
End With
End Sub

(Thanks Chip)

Cheers,

On Apr 1, 12:28*pm, Ivyleaf <ica...@gmail.com> wrote:
> Hi Andrew,
>
> ThisWorkbook.BuiltinDocumentProperties(PropertyName) will read the
> property from the file... use CustomDocumentProperties for a custom
> property, but be aware that this will return an error if the property
> doesn't exist.
>
> Once you have the properties read, just join 'em up however you want
> to make the filename. I would advise though that you sick in some well
> thought out error handling code to cater for:
>
> Properties not existing
> Properties being null length (if it hasn't been filled out for some
> reason)
> Properties containing characters that will be invalid in a file
> name... eg. you might want to do a Replace(NewFileName,"/","-") or
> something similar to ensure the save won't fail.
>
> Hope this helps.
>
> Cheers,
> Ivan.
>
> On Apr 1, 12:00*pm, Andrew <and...@discussions.microsoft.com> wrote:
>
>
>
> > How can I create a file name based on the entries in the "properties" section
> > of a document?
> > --
> > agibson- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      1st Apr 2008
Hi and thanks for the reply.

Not sure if I don't understand cause I'm a novice or if I didn't give enough
info.

I want to run a macro that will create the file name based on entries in the
properties section of a document. The file name composed of (for example):

Subject_Category_Title_status.xls

sorry if I did not give enough info at the begining.
--
agibson


"Ivyleaf" wrote:

> This code from Chip Pearson will help you with the property names:
>
> Sub Properties()
> Dim N As Long
> On Error Resume Next
> With ThisWorkbook.BuiltinDocumentProperties
> For N = 1 To .Count
> Cells(N, 1).Value = .Item(N).Name
> Cells(N, 2).Value = .Item(N).Value
> If Err.Number <> 0 Then
> Cells(N, 2).Value = CVErr(xlErrNA)
> Err.Clear
> End If
> Next N
> End With
> End Sub
>
> (Thanks Chip)
>
> Cheers,
>
> On Apr 1, 12:28 pm, Ivyleaf <ica...@gmail.com> wrote:
> > Hi Andrew,
> >
> > ThisWorkbook.BuiltinDocumentProperties(PropertyName) will read the
> > property from the file... use CustomDocumentProperties for a custom
> > property, but be aware that this will return an error if the property
> > doesn't exist.
> >
> > Once you have the properties read, just join 'em up however you want
> > to make the filename. I would advise though that you sick in some well
> > thought out error handling code to cater for:
> >
> > Properties not existing
> > Properties being null length (if it hasn't been filled out for some
> > reason)
> > Properties containing characters that will be invalid in a file
> > name... eg. you might want to do a Replace(NewFileName,"/","-") or
> > something similar to ensure the save won't fail.
> >
> > Hope this helps.
> >
> > Cheers,
> > Ivan.
> >
> > On Apr 1, 12:00 pm, Andrew <and...@discussions.microsoft.com> wrote:
> >
> >
> >
> > > How can I create a file name based on the entries in the "properties" section
> > > of a document?
> > > --
> > > agibson- Hide quoted text -

> >
> > - Show quoted text -

>
>

 
Reply With Quote
 
Ivyleaf
Guest
Posts: n/a
 
      1st Apr 2008
Hi Andy,

This isn't perfect, but I think it should give you a starting point.
Note that the "status" property is actually a 'custom' property and
hence will generate an error if it has not been initialised.

Dim errMsg() As String

Sub BuildFName()
Dim FName As String
ReDim errMsg(0)

On Error Resume Next

With ThisWorkbook
'Get Subject
FName = .BuiltinDocumentProperties("Subject")
If Err.Number Then ErrHandler ("Subject")

'Add Category
FName = FName & "_" & .BuiltinDocumentProperties("Category")
If Err.Number Then ErrHandler ("Category")

'Add Title
FName = FName & "_" & .BuiltinDocumentProperties("Title")
If Err.Number Then ErrHandler ("Title")

'Add Status
FName = FName & "_" & .CustomDocumentProperties("Status")
If Err.Number Then ErrHandler ("Status")

'Add extension
FName = Replace(FName, "/", "-") & ".xls"
End With

If Not ((Not errMsg) = True) Then
For i = 1 To UBound(errMsg)
errText = errText & IIf(i = 1, "", " & ") & errMsg(i)
Next
End If

MsgBox "Filename will be: " & FName & " but there were errors with
" & errText
End Sub

Sub ErrHandler(Property As String)
On Error Resume Next
Dim NewSize As Integer

NewSize = UBound(errMsg) + 1
ReDim Preserve errMsg(0 To NewSize)
errMsg(UBound(errMsg)) = Property
Err.Clear
End Sub

Cheers,
Ivan.

On Apr 1, 1:11*pm, Andrew <and...@discussions.microsoft.com> wrote:
> Hi and thanks for the reply.
>
> Not sure if I don't understand cause I'm a novice or if I didn't give enough
> info.
>
> I want to run a macro that will create the file name based on entries in the
> properties section of a document. *The file name composed of (for example):
>
> Subject_Category_Title_status.xls
>
> sorry if I did not give enough info at the begining.
> --
> agibson
>
>
>
> "Ivyleaf" wrote:
> > This code from Chip Pearson will help you with the property names:

>
> > Sub Properties()
> > * * Dim N As Long
> > * * On Error Resume Next
> > * * With ThisWorkbook.BuiltinDocumentProperties
> > * * For N = 1 To .Count
> > * * * * Cells(N, 1).Value = .Item(N).Name
> > * * * * Cells(N, 2).Value = .Item(N).Value
> > * * * * If Err.Number <> 0 Then
> > * * * * * * Cells(N, 2).Value = CVErr(xlErrNA)
> > * * * * * * Err.Clear
> > * * * * End If
> > * * Next N
> > * * End With
> > End Sub

>
> > (Thanks Chip)

>
> > Cheers,

>
> > On Apr 1, 12:28 pm, Ivyleaf <ica...@gmail.com> wrote:
> > > Hi Andrew,

>
> > > ThisWorkbook.BuiltinDocumentProperties(PropertyName) will read the
> > > property from the file... use CustomDocumentProperties for a custom
> > > property, but be aware that this will return an error if the property
> > > doesn't exist.

>
> > > Once you have the properties read, just join 'em up however you want
> > > to make the filename. I would advise though that you sick in some well
> > > thought out error handling code to cater for:

>
> > > Properties not existing
> > > Properties being null length (if it hasn't been filled out for some
> > > reason)
> > > Properties containing characters that will be invalid in a file
> > > name... eg. you might want to do a Replace(NewFileName,"/","-") or
> > > something similar to ensure the save won't fail.

>
> > > Hope this helps.

>
> > > Cheers,
> > > Ivan.

>
> > > On Apr 1, 12:00 pm, Andrew <and...@discussions.microsoft.com> wrote:

>
> > > > How can I create a file name based on the entries in the "properties" section
> > > > of a document?
> > > > --
> > > > agibson- Hide quoted text -

>
> > > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      1st Apr 2008
I'll try it

thanks
--
agibson


"Ivyleaf" wrote:

> Hi Andy,
>
> This isn't perfect, but I think it should give you a starting point.
> Note that the "status" property is actually a 'custom' property and
> hence will generate an error if it has not been initialised.
>
> Dim errMsg() As String
>
> Sub BuildFName()
> Dim FName As String
> ReDim errMsg(0)
>
> On Error Resume Next
>
> With ThisWorkbook
> 'Get Subject
> FName = .BuiltinDocumentProperties("Subject")
> If Err.Number Then ErrHandler ("Subject")
>
> 'Add Category
> FName = FName & "_" & .BuiltinDocumentProperties("Category")
> If Err.Number Then ErrHandler ("Category")
>
> 'Add Title
> FName = FName & "_" & .BuiltinDocumentProperties("Title")
> If Err.Number Then ErrHandler ("Title")
>
> 'Add Status
> FName = FName & "_" & .CustomDocumentProperties("Status")
> If Err.Number Then ErrHandler ("Status")
>
> 'Add extension
> FName = Replace(FName, "/", "-") & ".xls"
> End With
>
> If Not ((Not errMsg) = True) Then
> For i = 1 To UBound(errMsg)
> errText = errText & IIf(i = 1, "", " & ") & errMsg(i)
> Next
> End If
>
> MsgBox "Filename will be: " & FName & " but there were errors with
> " & errText
> End Sub
>
> Sub ErrHandler(Property As String)
> On Error Resume Next
> Dim NewSize As Integer
>
> NewSize = UBound(errMsg) + 1
> ReDim Preserve errMsg(0 To NewSize)
> errMsg(UBound(errMsg)) = Property
> Err.Clear
> End Sub
>
> Cheers,
> Ivan.
>
> On Apr 1, 1:11 pm, Andrew <and...@discussions.microsoft.com> wrote:
> > Hi and thanks for the reply.
> >
> > Not sure if I don't understand cause I'm a novice or if I didn't give enough
> > info.
> >
> > I want to run a macro that will create the file name based on entries in the
> > properties section of a document. The file name composed of (for example):
> >
> > Subject_Category_Title_status.xls
> >
> > sorry if I did not give enough info at the begining.
> > --
> > agibson
> >
> >
> >
> > "Ivyleaf" wrote:
> > > This code from Chip Pearson will help you with the property names:

> >
> > > Sub Properties()
> > > Dim N As Long
> > > On Error Resume Next
> > > With ThisWorkbook.BuiltinDocumentProperties
> > > For N = 1 To .Count
> > > Cells(N, 1).Value = .Item(N).Name
> > > Cells(N, 2).Value = .Item(N).Value
> > > If Err.Number <> 0 Then
> > > Cells(N, 2).Value = CVErr(xlErrNA)
> > > Err.Clear
> > > End If
> > > Next N
> > > End With
> > > End Sub

> >
> > > (Thanks Chip)

> >
> > > Cheers,

> >
> > > On Apr 1, 12:28 pm, Ivyleaf <ica...@gmail.com> wrote:
> > > > Hi Andrew,

> >
> > > > ThisWorkbook.BuiltinDocumentProperties(PropertyName) will read the
> > > > property from the file... use CustomDocumentProperties for a custom
> > > > property, but be aware that this will return an error if the property
> > > > doesn't exist.

> >
> > > > Once you have the properties read, just join 'em up however you want
> > > > to make the filename. I would advise though that you sick in some well
> > > > thought out error handling code to cater for:

> >
> > > > Properties not existing
> > > > Properties being null length (if it hasn't been filled out for some
> > > > reason)
> > > > Properties containing characters that will be invalid in a file
> > > > name... eg. you might want to do a Replace(NewFileName,"/","-") or
> > > > something similar to ensure the save won't fail.

> >
> > > > Hope this helps.

> >
> > > > Cheers,
> > > > Ivan.

> >
> > > > On Apr 1, 12:00 pm, Andrew <and...@discussions.microsoft.com> wrote:

> >
> > > > > How can I create a file name based on the entries in the "properties" section
> > > > > of a document?
> > > > > --
> > > > > agibson- Hide quoted text -

> >
> > > > - Show quoted text -- Hide quoted text -

> >
> > - Show quoted text -

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Path and FileName Steve Microsoft Excel Programming 2 4th Jun 2009 10:05 PM
Specifying Filename when creating PDf from Excel Workbook jlejehan Microsoft Excel Programming 7 7th Jun 2006 05:14 PM
Creating one file out of many, including the filename =?Utf-8?B?a3RtNDAw?= Microsoft Access External Data 21 29th Sep 2005 07:46 PM
Creating a Link from a Dragged filename SamSpade Microsoft VB .NET 0 26th May 2004 06:15 PM
Creating a complete filename for use with functions. cothrang Microsoft Excel Worksheet Functions 1 3rd Mar 2004 04:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:47 PM.