Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. ' want to get the filename of the csv file and paste it into current workbook
  2. ' Dim fso As New FileSystemObject
  3. ' Dim fileName As String
  4. ' fileName = fso.GetFileName(strFile)
  5. ' wb1("Main Page").Range("O26").Value = fileName
  6.  
  7. Sub ImportData()
  8.  
  9. Application.DisplayAlerts = False
  10.  
  11. Dim wb1 As Workbook
  12. Dim wb2 As Workbook
  13. Dim Sheet As Worksheet
  14. Dim PasteStart As Range
  15.  
  16. Set wb1 = ActiveWorkbook
  17. Set PasteStart = [RRimport!A1]
  18.  
  19. FileToOpen = Application.GetOpenFilename _
  20. (Title:="Please choose a Raw Data CSV File to Import", _
  21. FileFilter:="Report Files *.csv (*.csv),")
  22.  
  23. If FileToOpen = False Then
  24. MsgBox "No File Specified.", vbExclamation, "ERROR"
  25. Exit Sub
  26. Else
  27. Set wb2 = Workbooks.Open(fileName:=FileToOpen)
  28.  
  29. For Each Sheet In wb2.Sheets
  30. With Sheet.UsedRange
  31. .Copy PasteStart
  32. Set PasteStart = PasteStart.Offset(.Rows.Count)
  33. End With
  34. Next Sheet
  35.  
  36. End If
  37.  
  38. wb2.Close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement