Import sheet from a known file and location and rename

LittlegmoonBH

New Member
Joined
May 2, 2019
Messages
15
Hi Guys,

I’ve got some code that imports “Sheet1” from a file I needto select from a pop up box.

Sub ImportReport()

Dim Fname As String
Dim Wbk As Workbook

For Each Sheet InActiveWorkbook.Worksheets
If Sheet.Name ="Sheet1" Then
Sheet.Delete
End If
Next Sheet

Fname =Application.GetOpenFilename
Set Wbk =Workbooks.Open(Fname)
Wbk.Sheets("Sheet1").Copy ThisWorkBook.Sheets(1)
Wbk.Close False

Sheets("Sheet1").Select


End Sub

I know the name of the file, location and sheet name that I needto import, but I just can’t get anything to work. Once imported to my mastersheet, I want to change the name of the sheet to the name of the report I’musing it to produce.

Any help?

Thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How about
Code:
Sub LittlegmoonBH()
   Dim Pth As String, Fname As String
   Dim Wbk As Workbook
   
   Pth = "[COLOR=#ff0000]C:\MrExcel\[/COLOR]"
   Fname = "[COLOR=#ff0000]Book1.xlsm[/COLOR]"
   Set Wbk = Workbooks.Open(Pth & Fname)
   Wbk.Sheets("[COLOR=#ff0000]List[/COLOR]").Copy ThisWorkbook.Sheets(1)
   Wbk.Close False
   ActiveSheet.Name = "[COLOR=#ff0000]New name[/COLOR]"
End Sub
Change values in red to suit
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

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