Dynamic File Name and Import of Data

seanygy1uk

New Member
Joined
May 15, 2018
Messages
1
Hi,

I after some help to ease a procedure I need to carry out.

What I am after is:

in cell A1 it will have the file name I am looking for ie Packing 03.02.2018, this will be in a folder on a network drive

What I want it to do is load a sheet from that workbook to a sheet in this workbook so I can easily see data from the link above.

Any help is much appreciated
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Amend fPath to full path to your file
Amend sName to name of sheet to be copied
Amend extension if not xlsx

Place code in Standard module and run from sheet where cell A1 contains the file name
Code:
Sub InsertSheetFromWorkbook()
    Const fPath = "[COLOR=#ff0000]Q:\Folder\SubFolder\SubSubFolder[/COLOR]"
    Const sName = "[COLOR=#000080]MySheetName[/COLOR]"
    Dim fName As String, ws As Worksheet, wb As Workbook
    
    Set ws = ActiveSheet
    fName = ws.Range("A1").Value & "[COLOR=#006400].xlsx[/COLOR]"
    Set wb = Workbooks.Open(fPath & "" & fName)
    
    wb.Sheets(sName).Copy before:=ws
    wb.Close False
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
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