Macro to have someone find the document they want to open then open it and copy the data into this document

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I could do with you help,

I'm looking for a macro that when run gets you to select the file you want to open using the file explorer (it might be a csv or any excel document), then copy the page it opens on into this document sheet "Raw" A1
I want to copy everything including the headers and paste values if possible.

Please help if you can was supposed to have this finished today so i cant go home till its sorted (Going to be a long night)
Thanks
Tony
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I've used the following (I modified it for my specific use, but this is the basic version):

Code:
Sub GetFile()
   Dim Fname As Variant
   Dim SrcWbk As Workbook
   Dim DestWbk As Workbook
   Dim SheetName As String
   Dim lr As Long

   Application.ScreenUpdating = False
   Set DestWbk = ThisWorkbook
   Fname = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls*", Title:="Select a File")
   If Fname = False Then
   MsgBox "User Cancelled."
   End
   Else
   End If
   Set SrcWbk = Workbooks.Open(Fname)
   SheetName = ActiveSheet.Name
   SrcWbk.Sheets(SheetName).Copy DestWbk.Sheets("Sheet1")
   
   Application.DisplayAlerts = False

   SrcWbk.Close False

   Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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