Macro To Open Workbooks Of Multiple Specific Names?

May 2, 2014

I currently have a piece of code that opens all of the files in a folder that are called "*agent*", opens them and copies information. Now, these files come with numbers at the beginning which, are always the same. I only want to open certain files that begin with, for example, 801, 802, 803, 804, 805 and 806. How would I write this into my code? As you can see from the below code, it now looks for the files that all have "agent" in the name, but this is opening files that have that name but are not the right ones. Here is my current macro...

[Code] ....

I hope this isnt as simple as putting "MyFile = Dir(MyFolder & "*801*", "*802*")" etc.

View 2 Replies


ADVERTISEMENT

Open Multiple Workbooks With Variable Names

Aug 17, 2007

I have data spanning many files which are named with the date on which they were created (so there are 31 files for August).
For example:
PL080107, PL080207, PL080307, PL080407...)

I'm trying to compile all of my data into one workbook, and have the macro to append each file to a list. Now I need the macro to either OPEN each file, or ACTIVATE each file so that the rest of the Macro can grab the necessary data.

I say Open or Activate, because I can MANUALLY Open a full month's worth of files if it's easier code. If not, I would like it to open and close each workbook on its own.

I have over 7 month's worth, so opening 31 files 7 times is better than opening over 200 files individually!

View 5 Replies View Related

Macro To Find Replace Specific Text In Multiple Sheet Names

Sep 13, 2010

I need a macro that will look for a specific text string in the tab names of the workbook and replace it with a new specified text string (leaving the rest of the existing tab names). In other words, a simple find/replace but applied to all tab names in the workbook rather than cells. Ideally, I'd like it to pop up something and ask for the text to find and the text to replace it with, so I don't have to edit the macro itself each time I want to use it, but editing the macro each time is fine. Either way will be wonderful.

View 9 Replies View Related

Macro To Open Specific File By Searching Multiple Folders

Oct 11, 2013

I am trying to write a macro to open a specific file, but need to search multiple folders within folders to find it.

The file name I need to open is "Escalation Adherence-Details " & Format(Date, "mm-dd-yy") & ".xlsx".

I need to drill down to the Adherence Report folder and then have the macro search through folders for each year (2012, 2013, 2014, 2015, etc) and then each month within each year (1 January, 2 February, 3 March, etc), at which point I would then find that day's file.

So far I have the following:

Code:
Sub Open_ESCL_Report()

Workbooks.Open Filename:=*****.****.****.******.comsharesPurchasingTeam XEscalationAdherence Report & "Escalation Adherence-Details " & Format(Date, "mm-dd-yy") & ".xlsx"
End Sub

Each file is stored in it's respective month folder as .....Adherence Report(Year)(Month)(File).xlsx

View 3 Replies View Related

How To Search Multiple Workbooks For A Specific Value In A Specific Cell

Sep 14, 2008

I'm trying to search through multiple worksheets (that are closed) to see if a value in cell B12 (of every worksheet) matches a value in a seperate worksheet (which is in a seperate workbook)

View 14 Replies View Related

Enabling Manual Calculation On One Specific Workbook But All Other Open Workbooks Remain On

Mar 24, 2014

I want a specific workbook to be always on manual but when I open other workbooks I want them to remain on automatic even though the first workbook is set on manual through vba code. Is that possible to be done?

This is the code I run:

Private Sub Workbook_Activate()
With Application
.Calculation = xlManual
.MaxChange = 0.001
.CalculateBeforeSave = False

[Code] .....

I know that Application. Calculation refers to all open workbooks but I don't know the code to specify the manual calculation to this workbook only while others are open.

View 7 Replies View Related

Create Multiple Workbooks With Names Based On List

Sep 2, 2007

I have some very tedious work to do in Excel:

table looks like following:
DepID name function
S1 a YY
S1 b XX
S1 c ww
S2 d oo
S3 e ii
S3 f ll
S4 t mm
. . . . . .. . . .
. . . . . .. . . .
. . . . . .. . . .

S7999 u ee
S7999 w aa

My task is to create new folders for each department according to DepID, which means if there are 7999 departments, I have to create 7999 folders, any VBA code can do this?

View 9 Replies View Related

How To Make Same Macro Run On Workbooks With Different Names

Apr 15, 2013

I tried recording a macro to automate some tasks I perform every day between two workbooks. While in one I want to go get data from the other. The problem I'm having is the name of the workbooks I want to run this on changes every time I download my data into Excel. The files always start with the same name but the date gets appended to it. Is there a way to modify the macro to just work with the two books I've got open?

View 3 Replies View Related

Import Range From Multiple Workbooks With Names Listed In Column

Mar 31, 2008

I have been trying to use a FOR EACH C ...... NEXT loop, where each cell in the range is the beginning of a worksheet name that I need to import.

What I have got so far is:

Sub FindMyFiles()
Dim fs As FileSearch
Dim ImportWB As Workbook
Dim MasterWB As Workbook

Set fs = Application.FileSearch
Set MasterWB = ThisWorkbook

View 4 Replies View Related

Open Multiple Workbooks And Insert Row

Nov 16, 2006

I need have a folder with subfolders.

I need a macro to go into each subfolder: Open each excel workbook (which will usually contain one sheet), and insert a blank new row at the top of each sheet (without overriding existing row), filling it with headings like January, Feb....December.

View 9 Replies View Related

Active Multiple Open Workbooks

Jul 18, 2007

I want to use a for command, but not include all the i's between two numbers. The reason is I want it to activate open workbooks that have similar names, like '110000 2007.xls', '120000 2007.xls', '130000 2007.xls', '150000 2007.xls' and so on.

I want my code to look something like this:

For i = 11, 12, 13, 15
Windows(10 * i & "000 2007.xls").Activate
'do stuff
Next i

Is there a way I can do this? Or use another command?

View 5 Replies View Related

VBA Macro - VLookup From 2 Workbooks With Changing Names

Feb 17, 2014

I have a user which needs to run a vlookup daily. There is some formatting involved, especially with 2 exported workbooks...

So I wanted to make her a macro to do it. So she exports 2 workbooks where the names change based off the date range she runs the data for.

I was thinking I wanted her to close excel completely, then run them in a specific order and do the vlookups based of Index Numbers.

I can do the entire macro except for the syntax of the vlookup. I think if i write what I need, you guys could put it in proper syntax:

=Vlookup(RC[-10],Workbooks(2).Sheets(1).Range(A:A),1,false)

View 2 Replies View Related

Excel 2010 :: VBA / Creating Multiple Workbooks From A Template And List Of Names?

Aug 20, 2013

The easiest way I can describe the scenario I am trying to create, is to use a company list of personnel (my index) and to generate a time-sheet workbook per person based on a pre-populated template. This time-sheet is saved as the persons name and has the persons name entered into cell D:10

I have a workbook which contains two worksheets;

1) An Index sheet which contains a list of names that I wish to use in Q16 downwards (note the length of this list will vary each time I run this)

2) A "template" sheet which I wish to duplicate in new workbooks

3) A second "data" sheet that I wish to copy across in new workbooks

I need a macro that will take the "template" and "data" sheets and copy it into a new workbook, renaming each new workbook to each name in my Index sheet. I also want that same Name to be copied into cell reference D:10 of the "template" each time.

The end result is that I should have a series of new files generated and saved which are named the same as the Index list, with both the "Template" sheet and the "Data" sheet present, with the cell D:10 pre-populated with the Name provided in the "Template" sheet.

I'm using Excel 2010.

View 9 Replies View Related

List All Sheets Names From Multiple Workbooks & Copy Transpose Certain Columns

Oct 7, 2009

this may or may not be easy for some of you but its driving me nuts. Here's what I need to do.

1.Create a new workbook

2.Cycle through multiple workbooks and all worksheets within each workbook (all in the same folder). All workbooks will have the same structure.

3.Take the worksheet names and put them in rows

4.Take the data from the first column (column A) from the first worksheet of the first workbook and put them across the top (i.e. transpose the data). The first column will be the same in all workbooks so it doesn't matter where I get it from.

5.Copy the data from column E from each worksheet and paste them in rows in the new workbook (again transpose) corresponding to each worksheet.

6. Perform simple mathematical calculations at the end of each row.

I expect to have approximately 26 workbooks with a total of 7000 worksheets. In the target workbook (i.e. the new one), I expect there to be 7000 rows (corresponding to the 7000 worksheets) and about 260 columns.

The only reason I need to transpose stuff is because Excel 2007 doesn't have 7000 columns.

Here's an example of what it would look like.
Example worksheet (Input)-
Worksheet ABC
Col A Col E
1/1/2004 $25
1/8/2004 $30
1/15/2004 $15

Imagine another worksheet called LMN with the same ColA but different values in Col E.

Output workbook
ColA Columns B Column C Column D
Sheet 1/1/2004 1/8/ 2004 1/15/2004
ABC $25 $30 $15
LMN $xxx $yyy $zzz

View 7 Replies View Related

Open Multiple Protected Workbooks One Time

Dec 23, 2011

I'm looking for some way to open multiple protected workbooks in one time, these workbooks has been protected , but all with the same password. usually, when i open one workbook, open ,enter password, but there are so many of them that i want to open all these workbooks in the same time, the problem is each workbook showed a enter-password box, it so inefficient, i want all these protected workbooks show only one enter-password box.

View 2 Replies View Related

Open Multiple Workbooks & Copy Sheets

Jul 17, 2007

I have a created a main workbook with a macro that opens workbooks on a particular sheet from a list of workbook paths and filenames in the main workbook. The macro are suppose to copy the sheet and paste it into a sheet with a new name that I have defined from the list in the main workbook. I can get the macro to open the workbooks and close them. But I can't get the macro to copy the sheet into the main workbook.

I have attached the code and the workbook. I used slet_ark to delete previous sheet and hentark and henttekstfil to open the different workbooks.

The code I use are:

Public Sub Slet_ark()
Dim ark() As Variant
Dim Counter As Long
Dim FirstSheet As Long
Dim LastSheet As Long

View 3 Replies View Related

Open, Update And Close Multiple Workbooks

Sep 5, 2007

I have 30 workbooks closed and i want update a cell (f.e. b4) in all the workbooks.
Need code to open the files, update the data in that cell and close the workbook.

View 5 Replies View Related

VBA To Open Multiple Files With Different Unknown File Names?

Feb 28, 2014

I'm trying to build a macro to open multiple files at one time that will always be saved in a consistent drive. The problem is that sometimes there will only be one file for a month (ie only at month-end) and other times, there may also be additional files for different dates throughout the month. I wont know ahead of time how many files there will be, but they will always be saved in the same file name type that is "FILE DESCRIPTION MM-DD-YYYY". How can I build a loop that looks for a file on each possible day but doesn't error out if the file doesn't exist?

View 1 Replies View Related

Multiple Instances (VBA To Open 3 Workbooks In Their Own Session/instance)

Feb 2, 2010

I'd like to use VBA to open 3 workbooks in their own session/instance/etc of Excel 2007. Ideally, there will be one main workbook, that upon opening will subsequently open the other 3 workbooks.

Also, when I open that first main workbook, I will obviously have to enable macros to get any code to run. Is there a way to carry this enabling of macros over to the other sessions to avoid having to enable macros in all 3 other workbooks? (Changing my security settings isn't an option)

View 3 Replies View Related

Automatically Open, Copy, And Close Multiple Workbooks

Jul 26, 2006

I have 77 excel workbooks that are created each week, they are all in the same directory. I have to open each one and copy the data into a single workbook. The file names change slightly each week.

example: DIST_91124_GROWTH_PRODUCT XXX _07072006.xls The 07072006 is the week ending date and will change. Each of the 77 files has a different DIST_number.

Is there a way to automate this process, it takes me about 4 hours to do it manually.

View 9 Replies View Related

Macro Cycle Through Open Workbooks

Mar 29, 2013

I am trying to cycle ALL open workbooks so that I can choose the file to manipulate in subsequent code this is the code that I am utilizing furhter below

this is my code

VB:

For Each wb In Workbooks
If MsgBox("Do you want to do access this Workbook for the Update " & Chr(10) & Chr(10) & wb.Name, vbYesNo) = vbYes Then
wb.Activate
VI_wb = wb.Name
I = True
End If
Next wb

But for some reason it only loops through .xls and xlm workbooks BUT not .xlsx

is there a way that I can loop through any and all open workbooks.

The reason I do this is because my update are based on many numerous excel workbooks with differnet extentions, and naming conventions and many of the come via email, I cannot use the eact naming convention

View 1 Replies View Related

VBA Code To Run Macro In All Open Workbooks

Mar 12, 2014

I have a macro to get copy of sheet named "Doc Info" from workbook File 1 to active workbook.

I could do it for one file on any active workbook.

But what I would require is, upon executing this macro , i want this macro to get executed in all open workbooks( could be any numbers ).

I want to move copy of sheet from File 1 to all open workbooks ( which i am doing it manualy for every file )

All these open workbooks could be from any folder , wont be in same folder.

So logic is to execute my macro apply in all open workbooks in my computer.

Below is the code and i have attached file for test

HTML Code: 

Sub Copysheet()
Dim wSht As Worksheet
Dim wBk As Workbook
Dim wBk1 As Workbook

Set wBk = ActiveWorkbook 'Workbooks("File 2.xls")
Set wBk1 = Workbooks("File 1.xlsm")
Set wSht = wBk1.Sheets("Doc Info")

wSht.Copy before:=wBk.Sheets(1)

End Sub

View 2 Replies View Related

Macro To Merge Open Workbooks

Oct 15, 2008

the code necessary to merge all open workbooks (each contains only one worksheet) into 1 workbook made up of all of these individual worksheets?

View 2 Replies View Related

Macro To Save As Csv All Open Workbooks

Apr 14, 2009

i have this macro to save as a csv this macro only save the workbook the you are looking at, i will like for this macro to save as a csv all open workbooks preserving the name of the xls file.

Sub SAVE_AS_CSV()
Dim strFilename As String
strFilename = ActiveWorkbook.Name
strFilename = Left(strFilename, InStr(strFilename, ".")) & "csv"
ActiveWorkbook.SaveAs filename:=strFilename, FileFormat:=xlCSV
End Sub

View 2 Replies View Related

Macro To Open Passworded Workbooks

Jun 20, 2008

I've got a workbook ("Overview") which needs to refer to other workbooks (actually staff timesheets) which sit on a shared drive. All of these are passworded so only the staff member (and myself) can access them

As the workbook opens, it reads the links from the other files, and thus I have to enter the passwords one by one to update the data. I have come up with a macro which should do the job as follows:-

Private Sub Workbook_Open()

MsgBox "OK to run macro?"
' Message is here to let me know if the macro has run
Application.Workbooks.Open "S:LeaveTimesheetsFred 2008.xls", True, False, , "abc", "abc"
Application.Workbooks.Open "S:LeaveTimesheetsBill 2008.xls", True, False, , "def", "def"
Application.Workbooks.Open "S:LeaveTimesheetsTom 2008.xls", True, False, , "ghi", "ghi"
Application.Workbooks.Open "S:LeaveTimesheetsDick 2008.xls", True, False, , "jkl", "jkl"
Application.Workbooks.Open "S:LeaveTimesheetsHarry 2008.xls", True, False, , "mno", "mno"

End Sub

This seems to work, as it opens the workbooks. However, it doesn't run until after I've been manually prompted to enter the passwords. I'm guessing that the workbook links are taking precedence over the macro?

Is there either:-

a) A way to update the data into Overview without having to actually force the timesheets to open?

b) A way to make the macro run before the links update?

(btw I've not compromised the user passwords as Overview is itself passworded, so no-one can view the code!)

View 9 Replies View Related

Open Many Files/Workbooks & Run Macro

Oct 16, 2006

Here is what I'm doing:

-Open .xls file
-Run a macro (it works correctly when run by itself but I'm trying to speed things up)
-Save
-Close
-Open next file, and so on (I'll do this on no more than 200 files at a time all in the same folder)

Here is the code I am using: ....

View 9 Replies View Related

Macro Stops After Workbooks.Open

May 16, 2007

In the last week the following code has ceased to work, and I do not know why:

If TradeShow = True Then
ReportFile = " ANALYSIS PRINT (CS+T) MASTER.xls"
Else
ReportFile = "ANALYSIS PRINT (CS ONLY) MASTER.xls"
End If
Workbooks.Open Filename:=ReportFile, ReadOnly:=True
Worksheets("TRANSFER DATA").Select
PriceFile = "PRICE COMPARISON.xls"

The Workbooks.Open command executes, and the screen shows the cells of the new spreadsheet. Nothing else happens, and the cursor is sensitive to operator control, showing that Macro control has been lost. I have inserted a test 'MsgBox' after the .Open command, and not even that is executed - so I am certain that the .Open is in some way wiping out the Macro.

View 9 Replies View Related

Macro To Copy Data From Open Workbooks

Feb 12, 2009

I'm just starting out on my journey into VBA and this forum has been a valuable resource for picking up hints and tricks

I've decided to cut some corners and ask for help for the final piece of my current jigsaw - effectively this comes in two bits.

Part one:

I want to copy a sheet from two open workbooks and paste them into my active wookbook. Both source workbooks only have one sheet. I want a dialogue box to select the desired workbook, select and copy all data and then paste to a specified sheet (replacing the current data) in the destination workbook. I then want to select the other source workbook from the dialogue box and copy all data to a separate sheet in the destination workbook. I would like the dialogue box to have two options - Ok to select, copy and paste data, Cancel to end the macro.

Part two:

I want to copy a sheet from my source workbook and paste it as a separate sheet in a new workbook (a one page workbook would be ideal). I then want to save the new workbook in a specified location as "Data - Date" in the format 2009 02 12.

View 9 Replies View Related

Open Specified Workbooks & Change Cells Value Macro

Sep 27, 2006

I'm trying to write a macro that opens selected files, and updates cell F8 to a given value. But if I add more than one file it doesn't work... all in all I want to add 27 files to this macro.

at the moment it is

Sub UpdatePeriod()
'
' updateperiods1 Macro
' Macro recorded 27/09/2006 by navinderm
'
' Keyboard Shortcut: Ctrl+Shift+O
'
Workbooks.Open Filename:="G:....*.xls"

View 3 Replies View Related

Macro Code To Work Between 2 Open Workbooks

Jun 4, 2008

I am trying to simultaneously use two Excel workbooks that are open at the same time--one is calculations--other is data scenarios...one worksheet = one scenario: A macro uses "Set" to specify workbooks for "current_wb" and "wbkFrom". Code here

Set current_wb = ThisWorkbook
Dat_Fil = Application. GetOpenFilename
Workbooks.Open Dat_Fil
Set wbkFrom = Application.ActiveWorkbook

NOTE-Workbook object variables are declared outside any macro, and as "public." Code here

Public current_wb As Workbook
Public wbkFrom As Workbook

In a second macro I want to use the Current_wb and wbkFrom object variables I set in first macro, but get the following error: "object variable or With block variable not set" for any of the following statements in the second macro

current_wb.Activate
current_wb.Worksheets(1).Select
wbkFrom.Activate

I've declared the object variables as public in a different code module where there is no other code; I've tried declaring as public at the top of the code module that has my macros, but declared at top of code module and outside any macro; I've tried declaring the object variables as "static" variables (instead of "public") within the first macro. I can't figure this out.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved