- Katılım
- 27 Mayıs 2012
- Mesajlar
- 28
- Excel Vers. ve Dili
- Office 2016 - ENG
- Altın Üyelik Bitiş Tarihi
- 23.12.2020
Merhabalar herkese,
Asagida kod araciligiyla (internet uzerinden buldugum) belirtilen klasor icerisinde ki pdf dosyalarini kopyalayip, her pdf icin ayri sayfa actirip datalari ilgili sayfaya kaydetmek istiyorum, kod hem calismakta hemde calismamakta
nasil yani derseniz, renkli olarak isaretledigim kisim ayni sayfa mevcut ise silmekte bu nedenle, actigi sayfayi otomatik olarak sildiginden, kod sadece son sayfanin verisini dosyama aktarabilmekte, denedim ancak basarli olamadim, siz ustalarimdan konu hakkinda yardim alabilir miyim ? yardiminiz icin simdiden tesekkur ederim.
On Error Resume Next
Set wsOutp = Sheets(strFile)
On Error GoTo 0
If Not wsOutp Is Nothing Then
wsOutp.Delete
End If
Asagida kod araciligiyla (internet uzerinden buldugum) belirtilen klasor icerisinde ki pdf dosyalarini kopyalayip, her pdf icin ayri sayfa actirip datalari ilgili sayfaya kaydetmek istiyorum, kod hem calismakta hemde calismamakta
On Error Resume Next
Set wsOutp = Sheets(strFile)
On Error GoTo 0
If Not wsOutp Is Nothing Then
wsOutp.Delete
End If
Kod:
Option Explicit
Sub LoopThroughFiles()
Dim strFile As String, strPath As String
Dim colFiles As New Collection
Dim i As Integer
Dim rLog As Range, rOut As Range
Dim wsLog As Worksheet, wsOutp As Worksheet
Dim Activesheet As Worksheet
strPath = "C:\Users\PLHUTEK\Desktop\D\" 'pdf dosyalarinin yer aldigi klasor
strFile = Dir(strPath)
' Make a log sheet
On Error Resume Next
Set wsLog = Sheets("PdfProcessLog")
On Error GoTo 0
If wsLog Is Nothing Then
Set wsLog = ThisWorkbook.Sheets.Add(before:=Sheets(1))
wsLog.Name = "PdfProcessLog"
End If
Set rLog = wsLog.Range("A1")
rLog.CurrentRegion.ClearContents
rLog.Value = "PDF files copied to sheets"
' load all the files in a Collection
While strFile <> ""
If StrComp(Right(strFile, 3), "pdf", vbTextCompare) = 0 Then
colFiles.Add strFile
End If
strFile = Dir
Wend
Application.DisplayAlerts = False
'Loop through the pdf's stored in the collection
For i = 1 To colFiles.Count
'List filenames in Column A of the log sheet
rLog.Offset(i, 0).Value = colFiles(i)
strFile = Left(colFiles(i), Len(colFiles(i)) - 4)
' Delete sheet with filename if exists
On Error Resume Next
Set wsOutp = Sheets(strFile)
On Error GoTo 0
If Not wsOutp Is Nothing Then
wsOutp.Delete
End If
' (Re)Create the worksheet, give it the file name
Set wsOutp = ThisWorkbook.Sheets.Add(after:=wsLog)
wsOutp.Name = strFile
' Now open the file, and copy contents
OpenClosePDF colFiles(i), strPath
CopyStep wsOutp
Next i
Application.DisplayAlerts = True
End Sub
Sub OpenClosePDF(ByVal sAdobeFile As String, ByVal sPath As String)
Dim sAdobeApp As String
Dim vStartAdobe As Variant
sAdobeApp = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
vStartAdobe = Shell("" & sAdobeApp & " " & sPath & sAdobeFile & "", 1)
Application.Wait (Now + TimeValue("0:00:03"))
End Sub
Private Sub CopyStep(wsOutp As Worksheet)
' select all & copy
SendKeys "^a", True
SendKeys "^c", True
Application.Wait (Now + TimeValue("0:00:05"))
' Paste into the sheet from cell A1
AppActivate Title:=ThisWorkbook.Application.Caption
Activesheet.[A1].Select
SendKeys "^v"
Dim sKillAdobe As String
sKillAdobe = "TASKKILL /F /IM AcroRd32.exe"
Shell sKillAdobe, vbHide
End Sub