PDA

View Full Version : Designating Master file to excel



Jackel
09-30-2016, 12:24 PM
Hello everyone,

I am working on a project that requires me to copy and paste data from 50 different excel files, into one master. This master files name changes every month and am currently having to manually go in and change it for every line that it is used(about 10 lines within the code) every month. Is anyone familiar with some from of code that could let me just designate it to look at a "Master" and only have to change it once? It would really help! Thanks!

Would this be declaring a file name? Would that give the rest of the macro the ability to know to look at that one file?

Jackel
09-30-2016, 12:34 PM
Would this be declaring a file name? Would that give the rest of the macro the ability to know to look at that one file?

Paul_Hossler
09-30-2016, 01:36 PM
If the macro is in the 'Master.xlsm' then something like




ThisWorkbook.Worksheets("Master").Range("A1").Paste



would refer to that workbook

or you define a Const or Dim a variable to hold the name




Const MasterName as string = "Oct2016"

.....

Workbooks.Open Filename:="C:\Users\Data\" & MasterName & "-upd.xlsm"





Without know more about the macro, these are just guesses

SamT
10-02-2016, 09:13 AM
This master files name changes every month and am currently having to manually go in and change it for every line that it is used(about 10 lines within the code) every month.

Assuming it is the Master file

Dim MasterName As String
MasterName =Thisworkbook.Name

Or,as Paul said

Public Const MasterName As String = "Blah Blah"

Code somewhere

ThisMonthsMasterBookName = MasterName & " - " & Format(Date, "yy-mmm")