Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Open a pdf file code modification

I have gotten some code from Barb Reinhardt some time ago, but want to add
some more code to it. I want it to not only search that folder but all of the
subfolders in that same directory.

i know that the file applicationfile.search has a subdir property, but i
couldn't use that solution, so barb gave me this. How do i make this code
search the sub folders? Is there a property that does this?


Private Sub Lbx_file_names_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'
If (Lbx_file_names.Value < "") Then
'
Adobe_Filename_Pick = Lbx_file_names.Value
'
End If
'
If (Adobe_Filename_Pick < "") Then
'
Shell "C:\Program Files (x86)\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe" & _
(" " + MyFolder + Adobe_Filename_Pick), 1
'" X:\Omar\Finished_Flanges\14_600_RTJ_WN_S40.pdf", 1
'
' the following prints the document
'Application.SendKeys "^p~", False
'
End If
'
End Sub

Thanks,
Omar
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Open a pdf file code modification

Here's some sample code that will search subfolders.

'/=============================================/
' Sub Purpose: change from FileSearch to recursive DIR
' for 2007 comparability (Dir Recursive
' basic concept from MrExcel.com)
'/=============================================/
'
Public Sub ListFilesToDebug()
Dim blnSubFolders As Boolean
Dim k As Long, i As Long
Dim fso As Object
Dim strArr() As String
Dim strName As String
Dim strDirectory As String
Dim strFileNameFilter As String

On Error Resume Next

'- - - - - V A R I A B L E S - - - - - - - -
strDirectory = "C:\Temp\" 'look in this folder
blnSubFolders = True 'look in all sub folders if TRUE
strFileNameFilter = "*.XL*" 'filter on these files
'- - - - - - - - - - - - - - - - - - - - - -

'get 1st filename
strName = Dir(strDirectory & strFileNameFilter)

'put filenames into array
Do While strName < vbNullString
k = k + 1
ReDim Preserve strArr(k)
strArr(k) = strDirectory & strName
strName = Dir() 'get next file name
Loop

'get subfolder filenames if subfolder option selected
If blnSubFolders Then
Set fso = CreateObject("Scripting.FileSystemObject")
Call GetSubFolderFiles(fso.GetFolder(strDirectory), _
strArr(), k, strFileNameFilter)
End If

'show the results in the IMMEDIATE window
For i = 1 To k
Debug.Print strArr(i) & " - " & FileDateTime(strArr(i))
Next i

exit_Sub: 'generic exit sub routine
On Error Resume Next
Exit Sub

err_Sub: 'generic error message routine
Debug.Print "Error: " & Err.Number & " - (" & _
Err.Description & _
") - " & Now()
GoTo exit_Sub

End Sub

'/=============================================/
' Sub Purpose: recursive for filesearch 2007
'/=============================================/
'
Private Sub GetSubFolderFiles(ByRef Folder As Object, _
ByRef strArr() As String, ByRef i As Long, _
ByRef searchTerm As String)
Dim SubFolder As Object
Dim strName As String

On Error GoTo err_Sub

For Each SubFolder In Folder.SubFolders
'get 1st filename in subfolder
strName = _
Dir(SubFolder.Path & Application.PathSeparator & searchTerm)
'put filenames and file info in subfolders into array
Do While strName < vbNullString
i = i + 1
ReDim Preserve strArr(i)
strArr(i) = _
SubFolder.Path & Application.PathSeparator & strName
strName = Dir()
Loop
Call GetSubFolderFiles(SubFolder, strArr(), i, searchTerm)
Next

exit_Sub:
On Error Resume Next
Exit Sub

err_Sub:
Debug.Print "Error: " & Err.Number & " - (" & _
Err.Description & _
") - " & Now()
GoTo exit_Sub

End Sub
'/=============================================/


--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Omar" wrote:

I have gotten some code from Barb Reinhardt some time ago, but want to add
some more code to it. I want it to not only search that folder but all of the
subfolders in that same directory.

i know that the file applicationfile.search has a subdir property, but i
couldn't use that solution, so barb gave me this. How do i make this code
search the sub folders? Is there a property that does this?


Private Sub Lbx_file_names_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'
If (Lbx_file_names.Value < "") Then
'
Adobe_Filename_Pick = Lbx_file_names.Value
'
End If
'
If (Adobe_Filename_Pick < "") Then
'
Shell "C:\Program Files (x86)\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe" & _
(" " + MyFolder + Adobe_Filename_Pick), 1
'" X:\Omar\Finished_Flanges\14_600_RTJ_WN_S40.pdf", 1
'
' the following prints the document
'Application.SendKeys "^p~", False
'
End If
'
End Sub

Thanks,
Omar

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
code modification Rick Rothstein Excel Programming 0 April 19th 09 08:17 PM
modification to this code James Excel Discussion (Misc queries) 0 March 23rd 09 09:20 PM
Code Modification Randy Excel Programming 1 August 2nd 07 03:30 AM
Modification in the CODE to HIDE rows and columns that start with ZERO (code given) Thulasiram[_2_] Excel Programming 4 September 26th 06 04:15 AM
modification for the code srinivasan Excel Programming 2 August 20th 05 03:12 PM


All times are GMT +1. The time now is 03:10 AM.

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

About Us

"It's about Microsoft Excel"