Advertisement
mitchellpehora

ConvertWithDialog

Jun 20th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub ConvertwithDialog()
  2. Dim SummarySheet As Worksheet
  3.     ' Create a new workbook and set a variable to the first sheet.
  4.    Set SummarySheet = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
  5.     Dim f As Object
  6.     Dim srcWorkbook As Workbook
  7.  
  8. 'gets the files that the user wants to convert
  9. Set f = Application.FileDialog(3)
  10.  
  11. f.AllowMultiSelect = True
  12.  
  13.  
  14.  
  15. 'loops through each file performing the indicated operations
  16. If f.Show Then
  17.     For i = 1 To f.SelectedItems.Count
  18.  
  19.         sfile = Filename(f.SelectedItems(i), spath)
  20.  
  21.  
  22. Set srcWorkbook = Workbooks.Open(spath & sfile)
  23.        
  24.   Set sht = srcWorkbook.Worksheets(1)
  25. 'there's a lot more 'converting' to be done, but this is some of it
  26. sht.Range("A19:R90").Copy
  27. SummarySheet.Range("A2").PasteSpecial
  28.  
  29. SummarySheet.SaveAs (spath & "Converted " & sfile)
  30. Next
  31. End If
  32. SummarySheet.Close
  33. sht.Close
  34.  
  35. End Sub
  36.  
  37. 'provides the file name and path: https://stackoverflow.com/questions/14915179/ms-access-browse-for-file-and-get-file-name-and-path
  38. Public Function Filename(ByVal strPath As String, spath) As String
  39.     spath = Left(strPath, InStrRev(strPath, "\"))
  40.     Filename = Mid(strPath, InStrRev(strPath, "\") + 1)
  41. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement