Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 89329

Copying an opened CSV to another existing Workbook

$
0
0

Browse for an select a csv file, open that csv file, copy an entire sheet from that file not working - data is pasting to a new file instead

I want to create VBA code that will allow the user to browse for an select a .csv file, open it, copy an entire sheet from that file (it will have only one sheet in it, always), and paste that entire sheet into a sheet in the primary excel workbook called 'dec'.

Note that I'm not getting an error when the code runs. When I run it, I am able to browse for and select the .csv file. The data appears to be copied. But, it is pasting the data into a new workbook instead of into "This Workbook." And then, my code itself is getting pasted into the tab I designated (the 'dec' tab). I'm obviously doing something dumb ,but I can't see it today.

Sub Get_Data_From_File()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Browse for your Stripe download", FileFilter:="csv Files (*.csv*),*csv*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Copy
ThisWorkbook.Worksheets("dec").PasteSpecial xlPasteValues
OpenBook.Close SaveChanges:=False

End If
Application.ScreenUpdating = True
End Sub

Viewing all articles
Browse latest Browse all 89329

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>