简体   繁体   中英

vba application.filesearch update

so I'm trying to adapt some code i found for my needs. im pretty noob at VBA but i've run into a problem with the application.filesearch method not being available in 2010 now.

My excel workbook has a list of 20k hyperlinked .pdf files that im wanting to print out, however this script is just meant for me to click the macro and print out a few at a time, i have not written the part to print out the selected sections i would like to print, instead of the whole thing. but all my hyperlinks are in the A column.

Sub AutoPrintPDFs()

Dim Folder As String
Dim FName As String
Dim bk As Workbook
Dim strPath As String

strPath = ThisWorkbook.Path

With Application.FileSearch
.SearchSubFolders = True
.LookIn = strPath
.FileType = msoFileTypeAllFiles

If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count

If .FoundFiles(i) Like "*.pdf" Then
ActiveWorkbook.FollowHyperlink .FoundFiles(i), NewWindow:=True
Application.SendKeys "^p~", False
Application.Wait (Now + TimeValue("0:00:05"))
Application.SendKeys "%{F4}", False
Application.Wait (Now + TimeValue("0:00:05"))

End If

Next i
Else
MsgBox "All files done."
End If

End With
End Sub

I hope you can help me with this application.filesearch portion, ive been looking for a few hours and i just keep finding alternate functions very specific to other peoples scripts.

so ive been working on this and i gave up the macro method and went to a very elementary method of just single clicking each pdf.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count <> 1 Then Exit Sub
On Error Resume Next
    Application.ActiveWorkbook.FollowHyperlink Address:=CStr(Target.Value), NewWindow:=True
    Application.Wait (Now + TimeValue("0:00:03"))
    Application.SendKeys "^p~", False
    Application.Wait (Now + TimeValue("0:00:05"))
    Application.SendKeys "%{F4}", False
End Sub

I would be very interested in any other recommendations on how to make this more user friendly and/or learn API focus so i might have a dialog box to confirm if i would like to print the selected pdf.

i did have a dialog setup but i couldn't figure out how to get the focus back on the adobe reader once i clicked to confirm the dialog box, i did put a delay in the script to where i could click back to the adobe reader to send the keys, but manually i was faster than the script so i opted not to utilize it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM