Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Loop through each Excel file in folder
- Do While myFile <> ""
- 'Set variable equal to opened workbook
- Set wb = Workbooks.Open(Filename:=myPath & myFile)
- 'Ensure Workbook has opened before moving on to next line of code
- DoEvents
- *******'Do this to Opened Worksheet*****
- wb.Activate
- Dim strFilename, strDirname, strPathname, strDefpath As String
- On Error Resume Next ' If directory exist goto next line
- strDirname = Range("A6").Value ' New directory name
- strFilename = Range("A6").Value & " Rater" & Range("C15").Value 'New file name
- strDefpath = "C:UsersKaelDocuments" 'Default path name
- If IsEmpty(strDirname) Then Exit Sub
- If IsEmpty(strFilename) Then Exit Sub
- MkDir strDefpath & "" & strDirname
- strPathname = strDefpath & "" & strDirname & "" & strFilename 'create total string
- ActiveWorkbook.SaveAs Filename:=strPathname & ".pdf", _
- FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:="", WriteResPassword:="", _
- ReadOnlyRecommended:=False, CreateBackup:=False
- 'Save and Close Workbook
- wb.Close SaveChanges:=True
- 'Ensure Workbook has closed before moving on to next line of code
- DoEvents
- 'Get next file name
- myFile = Dir
- Loop
Add Comment
Please, Sign In to add comment