Importing data to Master File that has a changing name

Kieran1995

New Member
Joined
Mar 12, 2018
Messages
3
Hi,

I'm trying to copy and paste data from a selected workbook into my master file. One main problem I'm having is getting back to the master file, the reason being is that the name of the master file changes each month to whatever month it's being run in e.g. "March Master File" for this month "April Master File" when I run it next month. I have tried getting back to the file by referencing a dynamic file path but it doesn't work. Any suggestions on if there's an easier way of writing this and not having to refer to a file path?

This is what I got so far:

Code:
Sub ImportRepurchData()
    Dim combinedBook As Workbook
    Dim filter As String
    Dim caption As String
    Dim combinedFilename As String
    Dim combinedWorkbook As Workbook
    Dim targetWorkbook As Workbook
    
    TEMPLATEFile = Sheets("Dynamic").Range("ImportRepurch")
    
    
' Open Source Data
    
    Set targetWorkbook = Application.ActiveWorkbook
    
    filter = "Text files (*.xlsx),*.xlsx"
    caption = "Please Select an input file"
    combinedFilename = Application.GetOpenFilename(filter, , caption)
    Set combinedWorkbook = Application.Workbooks.Open(combinedFilename)
    
' Paste Source Data into original workbook
    
    Range("P4:P100000,AL4:AL100000").Select
    Selection.Copy
    
    Windows(TEMPLATEFile).Activate
        
    Sheets("Input Sched-Unsched Split").Select
    Range("B9:B100000,C9:C100000").Select
    ActiveSheet.Paste
    
    combinedWorkbook.Close
    
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,213,562
Messages
6,114,322
Members
448,564
Latest member
ED38

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