How to change VBA code for excel 2013

merveak

New Member
Joined
Jan 20, 2016
Messages
12
Hello All,

I have a VBA code that is written for excel 2003. Now we work with Excel 2013 and the code does not work.
I do not have any experience about VBA codes. Any help is appreciated!

Code:

"With Application.FileSearch
.LookIn = sPDFPath 'arama yapılan dizin
.SearchSubFolders = False 'alt klasörler aransın mı
'.FileType = msoFileTypeExcelWorkbooks aranacak dosya türleri
.Filename = "*.pdf" 'aranacak dosya isimleri/uzantıları
If .Execute() > 0 Then
'MsgBox .FoundFiles.Count & " adet dosya bulundu."
For i = 1 To .FoundFiles.Count
OutMail.Attachments.Add .FoundFiles(i)
Next i
Else
MsgBox "Hiç dosya bulunamadı.", vbCritical
End If
End With

.Display

'.Text = "Konu kisminda belirtilen dokumanlarin dagitimi ilgili bolumlere yapilmistir.OK/Onay maili donulmesi."
End With
Set OutMail = Nothing
Set OutApp = Nothing
Sheets("sevkler").Protect Password:="0000"
ThisWorkbook.Save
' SendKeys "^v"
End Sub"
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I believe this code will replace the code you have posted above. Test on a copy of your workbook.

Code:
Dim ofldr As Object
Dim ofile As Object
Dim FSO As Object
Dim varyFiles() As Variant
Dim lFileIndex As Long

Set FSO = CreateObject("Scripting.FileSystemObject")
Set ofldr = FSO.GetFolder(sPDFPath)

If ofldr.Files.Count > 0 Then
    For Each ofile In ofldr.Files
        If UCase(Mid(ofile.shortname, InStrRev(ofile.shortname, ".") + 1)) = "PDF" Then
            lFileIndex = lFileIndex + 1
            ReDim Preserve varyFiles(1 To lFileIndex)
            varyFiles(lFileIndex) = ofile.Path
        End If
    Next
End If

If lFileIndex > 0 Then
    For i = 1 To lFileIndex
        OutMail.Attachments.Add varyFiles(lFileIndex)
    Next i
    Else
        MsgBox "Hiç dosya bulunamadi.", vbCritical
    End If
End If
    
.Display

'.Text = "Konu kisminda belirtilen dokumanlarin dagitimi ilgili bolumlere yapilmistir.OK/Onay maili donulmesi."
End With

Set ofldr = Nothing
Set FSO = Nothing
Set OutMail = Nothing
Set OutApp = Nothing

Sheets("sevkler").Protect Password:="0000"
ThisWorkbook.Save
' SendKeys "^v"

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

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