Guest User

Untitled

a guest
Mar 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. 'Loop through each Excel file in folder
  2. Do While myFile <> ""
  3. 'Set variable equal to opened workbook
  4. Set wb = Workbooks.Open(Filename:=myPath & myFile)
  5.  
  6. 'Ensure Workbook has opened before moving on to next line of code
  7. DoEvents
  8.  
  9. *******'Do this to Opened Worksheet*****
  10. wb.Activate
  11.  
  12. Dim strFilename, strDirname, strPathname, strDefpath As String
  13. On Error Resume Next ' If directory exist goto next line
  14. strDirname = Range("A6").Value ' New directory name
  15.  
  16. strFilename = Range("A6").Value & " Rater" & Range("C15").Value 'New file name
  17. strDefpath = "C:UsersKaelDocuments" 'Default path name
  18. If IsEmpty(strDirname) Then Exit Sub
  19. If IsEmpty(strFilename) Then Exit Sub
  20.  
  21. MkDir strDefpath & "" & strDirname
  22. strPathname = strDefpath & "" & strDirname & "" & strFilename 'create total string
  23.  
  24. ActiveWorkbook.SaveAs Filename:=strPathname & ".pdf", _
  25. FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:="", WriteResPassword:="", _
  26. ReadOnlyRecommended:=False, CreateBackup:=False
  27.  
  28. 'Save and Close Workbook
  29. wb.Close SaveChanges:=True
  30.  
  31. 'Ensure Workbook has closed before moving on to next line of code
  32. DoEvents
  33.  
  34. 'Get next file name
  35. myFile = Dir
  36. Loop
Add Comment
Please, Sign In to add comment