Advertisement
mitchellpehora

ConvertNoDialog

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