Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compare file names to folder contents


Hi-

In an Excel file I have a column of PDF file names; e.g., aaA.pdf
AbC.pdf; 123.pdf. The -actual- PDFs should be in a folder on m
desktop. I'd like a way to compare the list of file names to the folde
contents to verify that the PDFs are in fact in my desktop folder.

For each file name in the Excel doc, can a macro search for a matchin
PDF file in my desktop folder and place a "yes" or "no" in the adjacen
column?

Thank you

--
marle
-----------------------------------------------------------------------
marlea's Profile: http://www.excelforum.com/member.php...fo&userid=2620
View this thread: http://www.excelforum.com/showthread.php?threadid=52289

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Compare file names to folder contents

Here is one approach. Assuming that the folder on your desktop where the
files to check is located is named "Test", create the user defined function
below in a module. Then if your column of file names is in A, you just
enter
=FileInDeskFldr(A1)
and drag the function down to get results for the entire column. The
function returns True or False but you can nest it in an IF function and
have it deliver "yes" or "no" if you want.


Function FileInDeskFldr(fName As String) As Boolean

Const Desktop = &H10&

Dim strDsk As String
Dim strFldrPath As String

' Find path to the Folder on the Desktop
Set objShell = CreateObject("Shell.Application")
Set objFolderDsk = objShell.Namespace(Desktop)
strDsk = objFolderDsk.Self.Path
strFldrPath = strDsk & "\Test"

' Verify existence of named file in the Desktop Folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFldrPath & "\" & fName) Then
FileInDeskFldr = True
Else
FileInDeskFldr = False
End If

End Function


Steve


"marlea" wrote in
message ...

Hi-

In an Excel file I have a column of PDF file names; e.g., aaA.pdf;
AbC.pdf; 123.pdf. The -actual- PDFs should be in a folder on my
desktop. I'd like a way to compare the list of file names to the folder
contents to verify that the PDFs are in fact in my desktop folder.

For each file name in the Excel doc, can a macro search for a matching
PDF file in my desktop folder and place a "yes" or "no" in the adjacent
column?

Thank you!


--
marlea
------------------------------------------------------------------------
marlea's Profile:
http://www.excelforum.com/member.php...o&userid=26209
View this thread: http://www.excelforum.com/showthread...hreadid=522891



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Compare file names to folder contents

I probably should have cleaned up the objects I created. The function above
will work fine but this is a bit better.

Function FileInDeskFldr(fName As String) As Boolean

Const Desktop = &H10&

Dim strDsk As String
Dim strFldrPath As String

' Find path to the Folder on the Desktop
Set objShell = CreateObject("Shell.Application")
Set objFolderDsk = objShell.Namespace(Desktop)
strDsk = objFolderDsk.Self.Path
strFldrPath = strDsk & "\Test"

' Verify existence of named file in the Desktop Folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFldrPath & "\" & fName) Then
FileInDeskFldr = True
Else
FileInDeskFldr = False
End If

Set objFolderDsk = Nothing
Set objShell = Nothing
Set objFSO = Nothing

End Function


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compare file names to folder contents


Hi Steve-

Thanks for the reply. I tried the function and when I dragged it ove
the cells, I got this: "#VALUE!".

I'm wondering if this has something to do with the fact that I'm on
Mac--perhaps the path to the desktop folder has to be define
differently? Unfortunately, I'm not sure how to resolve this.

I'd appreciate any help you could offer. Thanks

--
marle
-----------------------------------------------------------------------
marlea's Profile: http://www.excelforum.com/member.php...fo&userid=2620
View this thread: http://www.excelforum.com/showthread.php?threadid=52289

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
How to create a list of file names within a folder in Microsoft Ex Seablue Excel Discussion (Misc queries) 2 April 9th 07 08:44 PM
Need a macro to include file names in a folder to excel sheet anil Excel Discussion (Misc queries) 0 March 12th 07 09:10 AM
Can I insert a file or folder names in Excel cells? Inserting file or folder names in cells. Excel Discussion (Misc queries) 1 October 6th 05 11:30 PM
Change names of files in a folder to match names in Excel Column saybut Excel Programming 4 February 9th 04 06:26 PM
Extract file names last save info from a Folder Harapa Excel Programming 0 November 16th 03 04:33 PM


All times are GMT +1. The time now is 10:23 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"