Hello, My name is Piyush and I'm new here and VBA.
So, I wanna convert PDF file to Excel format but everytime I press the macro it just open the PDF file copy what's inside that and paste it in Excel but I'm getting an error at the end (attaching screenshot below).
Sorry if I'm missing something I'm new in this and I'm editing an old script made by someone else.
So, I wanna convert PDF file to Excel format but everytime I press the macro it just open the PDF file copy what's inside that and paste it in Excel but I'm getting an error at the end (attaching screenshot below).
Sorry if I'm missing something I'm new in this and I'm editing an old script made by someone else.
VBA Code:
Sub dd()
Dim sFilePath As String
Dim sFilename As String
Dim ws As Worksheet
Dim sFolder As String
Dim sFilename_1 As String
sFilePath = ThisWorkbook.path
sFilename = Dir(sFilePath & "\*.pdf")
If Len(sFilename) = 0 Then
' Open the select folder prompt
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then ' if OK is pressed
sFolder = .SelectedItems(1)
End If
End With
sFilename_1 = Dir(sFolder & "\*.pdf")
If Len(sFilename_1) = 0 Then
MsgBox "No pdf files are available"
Exit Sub
End If
Do While Len(sFilename_1) > 0
Application.DisplayAlerts = False
ActiveWorkbook.FollowHyperlink sFolder & "\" & sFilename_1, NewWindow:=True
Application.DisplayAlerts = True
Application.Wait Now + TimeValue("00:00:1")
Application.SendKeys ("%{V}{P}{DOWN}")
Application.SendKeys ("~")
Application.Wait Now + TimeValue("00:00:1")
Application.SendKeys ("^a")
Application.Wait Now + TimeValue("00:00:1")
Application.SendKeys ("^a")
Application.SendKeys ("^c")
Application.Wait Now + TimeValue("00:00:1")
Application.SendKeys "%{F4}", True
Application.Wait Now + TimeValue("00:00:1")
Application.ScreenUpdating = False
Set ws = ThisWorkbook.Sheets("Data Fill")
ThisWorkbook.Activate
Sheets("Data Fill").Select
ws.Columns("AC:AC").ClearContents
ws.Range("AC1").Select
ws.Paste
Last_Row = Cells(Rows.Count, 29).End(xlUp).Row
Range("AD1").Select
Range("AD1").Value = "=ADDRESS(2,MATCH(RIGHT(AC4,LEN(AC4)-6),A1:L1,0))"
Range("AD2").Value = "=ADDRESS(MATCH(Q18,AC:AC,0),29)"
Range(Range("AD2").Value & ":AC" & Last_Row).Select
Selection.Cut
Range("AC17").Select
ActiveSheet.Paste
Last_Row = Cells(Rows.Count, 29).End(xlUp).Row
Range("AD3").Value = "=ADDRESS(MATCH(Q59,AC:AC,0),29)"
Range(Range("AD3").Value & ":AC" & Last_Row).Select
Selection.Cut
Range("AC58").Select
ActiveSheet.Paste
Last_Row = Cells(Rows.Count, 29).End(xlUp).Row
ws.Range("AC1:AC" & Last_Row).Select
Selection.Copy
Sheet1.Select
Range(Sheets("Data Fill").Range("AD1").Value).Select
ActiveSheet.Paste
Application.ScreenUpdating = True
sFilename_1 = Dir
Loop
End If
Do While Len(sFilename) > 0
Application.DisplayAlerts = False
ActiveWorkbook.FollowHyperlink sFilename, NewWindow:=True
Application.DisplayAlerts = True
Application.Wait Now + TimeValue("00:00:1")
Application.SendKeys ("%{V}{P}{DOWN}")
Application.SendKeys ("~")
Application.Wait Now + TimeValue("00:00:1")
Application.SendKeys ("^a")
Application.Wait Now + TimeValue("00:00:1")
Application.SendKeys ("^a")
Application.SendKeys ("^c")
Application.Wait Now + TimeValue("00:00:1")
Application.SendKeys "%{F4}", True
Application.Wait Now + TimeValue("00:00:1")
Application.ScreenUpdating = False
Set ws = ThisWorkbook.Sheets("Data Fill")
ThisWorkbook.Activate
Sheets("Data Fill").Select
ws.Range("AC1:AC500").ClearContents
ws.Range("AD1:AD3").ClearContents
Range("AC1").Select
ws.Paste
Last_Row = Cells(Rows.Count, 29).End(xlUp).Row
Range("AD1").Select
Range("AD1").Value = "=ADDRESS(2,MATCH(RIGHT(AC4,LEN(AC4)-6),A1:L1,0))"
Range("AD2").Value = "=ADDRESS(MATCH(Q18,AC:AC,0),29)"
Range(Range("AD2").Value & ":AC" & Last_Row).Select
Selection.Cut
Range("AC17").Select
ws.Paste
Last_Row = Cells(Rows.Count, 29).End(xlUp).Row
Range("AD3").Value = "=ADDRESS(MATCH(Q59,AC:AC,0),29)"
Range(Range("AD3").Value & ":AC" & Last_Row).Select
Selection.Cut
Range("AC58").Select
ws.Paste
Last_Row = Cells(Rows.Count, 29).End(xlUp).Row
ws.Range("AC1:AC" & Last_Row).Select
Selection.Copy
Sheet1.Select
Range(Sheets("Data Fill").Range("AD1").Value).Select
ActiveSheet.Paste
Application.ScreenUpdating = True
sFilename = Dir
Loop
Sheet1.Select
Range("Q12:Q17").Select
Selection.Copy
Range("A12:K17").Select
ActiveSheet.Paste
Range("Q53:Q58").Select
Application.CutCopyMode = False
Selection.Copy
Range("A53:K58").Select
ActiveSheet.Paste
Range("A77:L200").ClearContents
End Sub