Advertisement
csetariq

pdf2docx

Jul 1st, 2021
2,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Main()
  2.    
  3.     Dim Source_Folder_Path As String, Target_Folder_Path As String
  4.     Dim File_Names As String
  5.     Dim doc As Document
  6.    
  7.     '// Step 1. Assign Folder Paths
  8.    Source_Folder_Path = "C:\Users\Tariq.Kamardeen\Downloads\Source"
  9.     Target_Folder_Path = "C:\Users\Tariq.Kamardeen\Downloads\Target"
  10.    
  11.     If Right(Source_Folder_Path, 1) <> "\" Then
  12.         Source_Folder_Path = Source_Folder_Path & "\"
  13.     End If
  14.    
  15.     If Right(Target_Folder_Path, 1) <> "\" Then
  16.         Target_Folder_Path = Target_Folder_Path & "\"
  17.     End If
  18.    
  19.     '// Step 2. Grad all the PDF files
  20.    
  21.     File_Names = Dir(Source_Folder_Path & "*.pdf")
  22.    
  23.     Application.DisplayAlerts = wdAlertsNone
  24.    
  25.     Do While File_Names <> ""
  26.        
  27.         Set doc = Documents.Open(Source_Folder_Path & File_Names, False)
  28.        
  29.         '// Convert the PDF file to Word Doc
  30.        doc.SaveAs2 Target_Folder_Path & Replace(File_Names, ".pdf", ".docx"), wdFormatDocumentDefault
  31.         doc.Close False
  32.        
  33.         Set doc = Nothing
  34.        
  35.         File_Names = Dir()
  36.     Loop
  37.    
  38.     Application.DisplayAlerts = wdAlertsAll
  39.    
  40.     MsgBox "Conversion is finished"
  41. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement