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,194
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,215,133
Messages
6,123,234
Members
449,092
Latest member
SCleaveland

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