Prompt to open a CSV, merge it into the file (already open) that has the macro

SandsB

Well-known Member
Joined
Feb 13, 2007
Messages
731
Office Version
  1. 365
Platform
  1. Windows
User has a report open (File1.xlsx) and runs a macro to....
  1. Give the user a prompt to point to a file (Fileddddtttt.csv) - the file name contains the date and time so it changes every time it's created.
  2. Copy the worksheet in Fileddddtttt.csv to a tab named Daily in File1.xlsx.
  3. Fileddddtttt.csv doesn't need to stay open - just copied into File1.xlsx.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
User has a report open (File1.xlsx) and runs a macro to....
  1. Give the user a prompt to point to a file (Fileddddtttt.csv) - the file name contains the date and time so it changes every time it's created.
  2. Copy the worksheet in Fileddddtttt.csv to a tab named Daily in File1.xlsx.
  3. Fileddddtttt.csv doesn't need to stay open - just copied into File1.xlsx.
Hello Sands,
this is what I use to achieve a similar result, add as a button, or as part of another macro. You will need to change your paste destination.

VBA Code:
Sub Get_Data_From_File()
     If MsgBox("You will now open the file you want to add charges to, click OK to continue") = vbYes Then
End If
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
    FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files (*.csv*),*csv*")
    If FileToOpen <> False Then
        Set OpenBook = Application.Workbooks.Open(FileToOpen)
      
      
        Application.DisplayAlerts = False
'below is where you are copying from
        OpenBook.Sheets(1).Range("A1:W9999").Copy
'below is where you are pasting to, change "Pasted Import File" and Range to your destination
        ThisWorkbook.Worksheets("Pasted Import File").Range("A1").PasteSpecial xlPasteValues
        OpenBook.Close False
        Application.DisplayAlerts = True
      
      
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,877
Messages
6,175,138
Members
452,614
Latest member
MRSWIN2709

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top