Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 358
Default creating filename

How can I create a file name based on the entries in the "properties" section
of a document?
--
agibson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default creating filename

Hi Andrew,

ThisWorkbook.BuiltinDocumentProperties(PropertyNam e) 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 wrote:
How can I create a file name based on the entries in the "properties" section
of a document?
--
agibson


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default creating filename

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 wrote:
Hi Andrew,

ThisWorkbook.BuiltinDocumentProperties(PropertyNam e) 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 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 -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 358
Default creating filename

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 wrote:
Hi Andrew,

ThisWorkbook.BuiltinDocumentProperties(PropertyNam e) 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 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 -



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default creating filename

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 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 wrote:
Hi Andrew,


ThisWorkbook.BuiltinDocumentProperties(PropertyNam e) 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 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 -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 358
Default creating filename

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 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 wrote:
Hi Andrew,


ThisWorkbook.BuiltinDocumentProperties(PropertyNam e) 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 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a named range gives an error only when the filename is lo Adi[_2_] Excel Discussion (Misc queries) 1 September 15th 09 01:14 PM
Creating a Word filename shortcut in Excel Creating a Word shortcut in Excel Excel Discussion (Misc queries) 2 November 25th 07 10:33 PM
SaveAs Filename:=filename, FileFormat:=xlCSV Teddy[_3_] Excel Programming 2 May 29th 07 02:34 PM
Converting a Variable Filename to a Constant Filename Magnivy Excel Programming 2 August 15th 06 06:13 PM
Specifying Filename when creating PDf from Excel Workbook jlejehan[_7_] Excel Programming 7 June 7th 06 05:14 PM


All times are GMT +1. The time now is 02:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"