Here's a more cleaner code

Dim objFSO As Object 'FileSystemObject
Sub ExampleSub()

    Dim obj As Object 'Folder
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set obj = objFSO.GetFolder("C:\Folder")

    FolderRead obj

End Sub

Private Sub FolderRead(ByRef myFolder)

    Dim objFile As Object 'File
    Dim strPath As String
    Dim lngLoop As Long
    Dim strRootFolder As String
    Dim lngCount As Long

    strRootFolder = myFolder
    For Each objFile In myFolder.Files
        strPath = objFile.Path
        If InStr(1, "pdf tif", objFSO.GetExtensionName(objFile.Name)) Then
            lngLoop = lngLoop + 1
            ActiveSheet.Hyperlinks.Add Anchor:=Range("A" & lngLoop), _
               Address:=objFile.Path, TextToDisplay:=objFile.Name &
"          " & objFile
            Range("I" & lngLoop) = objFile.Name 'mer added
            Range("J" & lngLoop) = strRootFolder & "\" 'mer added
            lngCount = lngCount + 1
        End If
    Next objFile
    Range("E1") = "# Of Documents is: " & lngCount
    lngCount = 0
    lngLoop = 0

End Sub

Regards,

Sam Mathai Chacko

On Tue, Feb 21, 2012 at 8:37 PM, Dave <davidstev...@gmail.com> wrote:

> Thanks Don I tried it and its giving me a Syntax error. here is the
> line as I have it in the code.
>
> If Right(f.Name, 4) = ".pdf" OR If  Right(f.Name, 4) = ".tif" Then
>
> On Feb 21, 8:37 am, "dguillett1" <dguille...@gmail.com> wrote:
> > I would probably write this differently but try this
> >
> > If Right(f.Name, 4) = ".pdf" ORIf  Right(f.Name, 4) = ".tif" Then
> >
> > Don Guillett
> > SalesAid Software
> > dguille...@gmail.com
> >
> >
> >
> > -----Original Message-----
> > From: Dave
> > Sent: Tuesday, February 21, 2012 8:26 AM
> > To: MS EXCEL AND VBA MACROS
> > Subject: $$Excel-Macros$$ How to modify code to display .PDF & .TIF file
> > types as hyperlinks in Excel 2010 instead of just .PDF files.
> >
> > Hi,
> >
> > I have the following code which searches a folder and than displays
> > all the .PDF files as hyperlinks in the body of the Excel
> > spreadhsheet. I want to modify it so that it can display .TIF files
> > also. Can you please look at the code below and see if this can be
> > done. All help is appreciated.
> >
> > Private Sub FolderRead(ByRef myFolder)
> > Dim countf As String
> > countf = 0
> >    For Each f In myFolder.Files
> >     Var = f.Path
> >     If Right(f.Name, 4) = ".pdf" Then
> >         i = i + 1
> >         ActiveSheet.Hyperlinks.Add Anchor:=Range("A" & i), _
> >             Address:=f.Path, TextToDisplay:=f.Name & "          " & f
> >
> >         Range("I" & i) = f.Name 'mer added
> >         Range("J" & i) = rootfolder & "\" 'mer added
> >     countf = countf + 1
> >     End If
> >
> >    Next f
> >    Range("E1") = "# Of Documents is: " & countf
> > countf = 0
> > End Sub
> >
> > --
> > FORUM RULES (986+ members already BANNED for violation)
> >
> > 1) Use concise, accurate thread titles. Poor thread titles, like Please
> > Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
> will
> > not get quick attention or may not be answered.
> >
> > 2) Don't post a question in the thread of another member.
> >
> > 3) Don't post questions regarding breaking or bypassing any security
> > measure.
> >
> > 4) Acknowledge the responses you receive, good or bad.
> >
> > 5)  Cross-promotion of, or links to, forums competitive to this forum in
> > signatures are prohibited.
> >
> > NOTE  : Don't ever post personal or confidential data in a workbook.
> Forum
> > owners and members are not responsible for any loss.
> >
> >
> ---------------------------------------------------------------------------­---------------------------
> > To post to this group, send email to excel-macros@googlegroups.com-Hide 
> > quoted text -
> >
> > - Show quoted text -
>
> --
> FORUM RULES (986+ members already BANNED for violation)
>
> 1) Use concise, accurate thread titles. Poor thread titles, like Please
> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
> will not get quick attention or may not be answered.
>
> 2) Don't post a question in the thread of another member.
>
> 3) Don't post questions regarding breaking or bypassing any security
> measure.
>
> 4) Acknowledge the responses you receive, good or bad.
>
> 5)  Cross-promotion of, or links to, forums competitive to this forum in
> signatures are prohibited.
>
> NOTE  : Don't ever post personal or confidential data in a workbook. Forum
> owners and members are not responsible for any loss.
>
>
> ------------------------------------------------------------------------------------------------------
> To post to this group, send email to excel-macros@googlegroups.com
>



-- 
Sam Mathai Chacko

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

------------------------------------------------------------------------------------------------------
To post to this group, send email to excel-macros@googlegroups.com

Reply via email to