Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search on document type 1

Status
Not open for further replies.

cramd

Programmer
Mar 28, 2001
214
US
I need to perform a function on only documents with an extension of *.rtf. I searched the ".BuiltInDocumentProperties" but could not find any property that specifically points to the document type. Am I missing something here?
Thanks for any thoughts.
Diane
 
If the file is already opene, use Right(ActiveDocument.Name,3) to get the file name extension. Test for
Code:
If Right(ActiveDocument.Name,3) = "rtf"
& run function if true

If you're looping through a set of files on disk, use
Code:
l_sFilename = Dir("Pathname\*.rtf")
to get just the .rtf files returned
Open each
Code:
l_sFileName[/code & run your function

HTH (& this is what you meant ;-))

Cheers
Nikki
 
Nikki,
Your first example is what I needed, "Right(ActiveDocument.Name,3) is "rtf" " then process. Now could you explain--I tried your code and it worked instantly, but I assumed I would have to declare "RIGHT"---but I didn't. Apparently this is a keyword with activedocument. Do you know of a site that indicates all the possible arguments that are allowed with MSWORD references?
Once again--thanks for your help!
Diane
 
Hi Diane,

Glad it helped ;-). RIGHT is actually a standard text function of VBA. SearchVBA help for "returning strings from functions to get a complete list

Cheers
Nikki

PS - from the Excel VBA help:
Code:
Chr$     ChrB$     *Command$
CurDir$  Date$     Dir$
Error$   Format$   Hex$
Input$   InputB$   LCase$
Left$    LeftB$    LTrim$
Mid$     MidB$     Oct$
Right$   RightB$   RTrim$
Space$   Str$      String$
Time$    Trim$     UCase$
* May not be available in all applications.
 
I have a simular problem as above, but I need to do a recursive search through subdirectories. I can use the following....


Private Sub CommandButton1_Click()
Filename = Dir$("C:\htm\*.htm")
'Start File Search

Do While Filename <> &quot;&quot;
'this puts names on an excel worksheet but you could add them to an array and then loop thru the array
ActiveCell.Offset(r, 0) = Filename
r = r + 1
Filename = Dir$()
Loop
End Sub

but that only searches and lists the c:\htm directory in the htm directory there are other folders I need to list those as well the folders go at lease 7 deep. After that I need to open the file in a text editor and replace a string of code then resave it in the same location it was.


 
The FileSearch object is more powerful than the Dir function. You'll need to set the .SearchSubFolders property to true. Best way to learn is to check the help topic on the FileSearch object and play around with it - I think it has all you need to get the job done!
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top