Need helping Copying PDF files to a new directory

Status
Not open for further replies.

bbcjmr

New Member
Joined
Aug 29, 2019
Messages
2
Hello VBA Guru's, I have this code which I use to search a directory for a word doc and if it exist in the spreadsheet then it copies that file to a new directory and marks on the spreadsheet as moved, Recently we changed from Word docs to PDF files and I cant work out how to make it do the exact same thing for PDF files :(:(:(. Any assistance would be greatly appreciated

Sub CopyDocs()
Dim fldr As FileDialog
Dim sItem As String
Dim c As Object
Dim Path As String
Dim FName As String
Dim SPath As String
Dim wd As Word.Application
Set wd = CreateObject("word.application")
wd.Visible = False


Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With


With ActiveSheet
Lrow = ActiveSheet.Cells(1500, 2).End(xlUp).Row




For Each c In .Range("B2:B" & Lrow)
Path = sItem
FName = Dir(Path & "\*.doc*")
Do
If InStr(FName, c) > 0 And c <> "" Then
On Error Resume Next
MkDir (ThisWorkbook.Path & "" & ActiveSheet.Name)
MkDir (ThisWorkbook.Path & "" & ActiveSheet.Name & "\Review")
On Error Resume Next
If .Cells(c.Row, "L") = "" Then
On Error Resume Next
wd.Documents.Open Filename:=Path & "" & FName
wd.ActiveDocument.SaveAs (ThisWorkbook.Path & "" & ActiveSheet.Name & "\Review" & FName)
wd.ActiveDocument.Close
c.Offset(, 10) = "Moved"
End If
End If
FName = Dir()
Loop Until FName = ""
Next c
End With

NextCode: Exit Sub
wd.Quit
Set fldr = Nothing
Set wd = Nothing
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Duplicate to https://www.mrexcel.com/forum/excel-questions/1108506-need-helping-opening-pcf-files.html

Please do not post the same question multiple times. Questions of a duplicate nature will be locked or deleted, per #12 of the Forum Rules and points 6 & 7 of the Forum Use Guidelines.

Note that posts from new members are sometimes 'held back' until they are approved by a moderator. So in future, please be patient.

Any bumps, clarifications, or follow-ups should be posted to the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top