VBA To Open External Workbooks With Variable Filenames And Close

Nov 29, 2013

I'm trying to create a VBA macro which will open external workbooks in a specific folder. thes workbooks will have filenames which are identical to the value in cell B1 of my active workbook. Once open, I would use indirect to pull certain results from that external workbook and then close it. I have a separate macro already which runs through the list. I found a few examples online but they don't seem to work.

View 2 Replies


ADVERTISEMENT

Browse Directory, Open Specified Filenames Then Close

May 5, 2006

I have done a search in the forum, and there are many results on browsing directory and opening files, but they are not what I have in mind.

What I have is different folders for different months (e.g. “January”, “February’, “March” and so on), and in each folder I have the same file names (e.g., in “January” folder, I have files called A, B, C. In “February”, I also have files A, B, C but these are different from the files in other folders)

Basically I need a macro which can open a specific list of files.

So first step, the user should be able to browse the directory, then select a folder (no need to open, not sure if it makes any difference though). I need the user to be able to select different folders because the macro should work for the different months in different years.

For this, I have found this
Function GetFolderPath() As String
Dim oShell As Object
Set oShell = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please select folder", 0, "c:\")
If Not oShell Is Nothing Then
GetFolderPath = oShell.Items.Item.Path
Else
GetFolderPath = vbNullString
End If
Set oShell = Nothing
End Function...........

View 9 Replies View Related

VBA To Determine Filenames Of Open Workbooks

Sep 2, 2009

I have a userform which prompts a user to select two files from the directory. Once these two files are open I will extract data from one into the other, the only problem is these filenames will change and I need to be able to determine what their names are.

I have this code below:

Private Sub CommandButton1_Click()
FiletoOpen = Application.GetOpenFilename _
(Title:="Please choose a file", _
FileFilter:="Excel Files *.xls (*.xls),")

If FiletoOpen = False Then
MsgBox "No file specified."
Exit Sub
Else
Filename1 = FiletoOpen
TextBox1.Value = Filename1
End If

End Sub

If I could somehow extract the exact filename, not full path, from the variables Filename1 and Filename2 I would be fine I guess, I just don't know how to do that.

View 9 Replies View Related

Close All Open Workbooks Except......

Feb 25, 2008

I made an Excel based program that uses multiple workbooks with two main workbooks (“Master List” and “Products”) that all the others pull information from. I run into a problem when a user clicks the close X in the upper right hand corner and the entire application closes. I found some code that will let me close all the workbooks but one (the code is put in the “Products” workbook in the BeforeClose event).

For Each wb In Workbooks
If Not wb Is ThisWorkbook Then
wb.Close SaveChanges:=True
End If
Next wb

Is there a way to modify the code so it will close all the workbooks but the two main ones if someone clicks the close X button in the upper right hand corner?

View 3 Replies View Related

Dynamic Open/Close Of Workbooks Crashes

Dec 15, 2009

I'm working on developing a stock option trading system in Excel using a live data feed and VBA. It tends to crash after running flawlessly for a half hour to 2 hours. It seems to crash when loading a support workbook, so I was hoping you could take a peek at my code and see if there's a problem with the way I'm dynamically opening/closing workbooks.

In order to cope with limitations in the amount of live data that I'm accessing (through DDE with Reuters Station), I've split up the data I need into about 600 workbooks, which open when they're needed or close when they're not (through VBA). At any given time, about 35-40 of these workbooks are open.

The main workbook that uses all this live data and support workbooks is set to have the application recalculate every 5 seconds (automatic recalc crashes the program almost immediately). After that refresh, it calls other subroutines, including opening/closing these support workbooks:

View 14 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

Close Workbooks (with Variable Names) Without Saving

Mar 7, 2014

I have completed a long macro, and at the end of the macro I want to close a few workbooks automatically without saving. These workbooks have been assigned variable names.

Is there a command line I can use, that will not prompt the user to save?

Variables:
MARM_fileNM
MARC_fileNM
MAKT_fileNM
Temp_fileNM

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

Excel 2007 :: VBA To Save And Close All Open Workbooks Except Macro Workbook?

Mar 8, 2013

I have a macro that opens all workbooks from one directory and runs a macro for each workbook to clean up the data. I cannot figure out how to take all those open workbooks and save them to another directory and close the workbook. Also, I do not want the macro workbook (xlsm) to save. I only want it to close. I am working in 2007 Excel.

View 8 Replies View Related

Open Multiple Files From Array Of Filenames If Not Already Open VBA

Sep 15, 2014

I'm trying to open multiple files based on an array of WBnames that are on a 'Dashboard' tab, but I only want to open them if they are not already opened. The code below doesn't seem to check if they are open and just opens everything....

VB:
Sub OpenWorkbooks()
Dim WorkbookOpen()
Dim WBnames() As String 'Array of WorkBooks to be Open
Dim WorkbookCnt As Integer

[Code] .....

View 4 Replies View Related

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

Close Workbooks And Move In And Out Of Workbooks In VBA

Dec 27, 2009

Basically the main workbook opens 2 files at a time performs a calculate in the main workbook and then copies and pastes information in 3 ranges. Then closes the two open workbooks and loops and performs same operations until it hits the maximum loops. My macro is as follows and I have 3 question in capital letters.

View 3 Replies View Related

Referencing External Workbooks?

Jun 6, 2014

I'm trying to set-up a costing system as follows:

Each job has it's own xls file, this is a list of manually input costs and a total cost at the bottom (total is the same Cell reference: G24) for all xls files. The xls file is named the same as the job - F0001, F0002 etc.

At the end of every month we then want to create a master list xls file for all jobs being invoiced that month. This is a list of all the jobs - F0001, F0002 etc. In Column A, and the corresponding cost totals in column B.

In the master file we want to be able to type in the job reference to column A (i.e. the file names of the single job files -F0001, F0002 etc) and have the corresponding total for that reference display automatically in Column B (i.e. Cell G24 from file F0001 will display in the master file cell B1, when 'F0001' is typed in cell A1).

Ideally the master file would display all the individual entries automatically, so no need to input the job references either - simply scanning the directory for the other files present and creating a list automatically in the master file, alternatively it can get the job reference from Cell A1 in the individual job files, instead of from the file name.

View 2 Replies View Related

Hyperlink Function To External Workbooks

Sep 11, 2009

I'm trying to create a hyperlink that takes a user to a specific cell (or range of cells) in an external workbook, and I've run into bit of a roadblock. I've discovered that using the method:

=HYPERLINK("[\serverfolder....file.xls]worksheet!range","message")

works just fine as long as there are no spaces in the worksheet name. Unfortunately I am trying to link to an external worksheet with spaces in the name (which I am not allowed to edit).

View 2 Replies View Related

Several Links To External Workbooks That Cannot Be Found

Nov 15, 2006

I have several links to external workbooks that cannot be found...

I have deleted all Name references that posses a ref#

Also I have tried to change the source to the workbook that I am using, but I keep getting a message that says invalid reference to external workbook! In other words it won't let me change my source

I have several work books that I want to change there source, or even get rid of because I can't update them anyways and I don't think it matters if they are updated!

View 9 Replies View Related

Linking Multiple External Workbooks

Apr 12, 2007

I have a workbook called Pricing.xls that contains *multiple* external links. The Pricing WB summarized monthly data, the trick is that each month is in a different WB (*DEC06.xls), and the big problem is that there are dozens WBs a month.

I am using vlookups to get the data from external WBs.

The way that it is being done currently is; the formula is copied across month to month, and them manually editing the link in the formula bar. This seems to half work, but causes Excel grief. Is there a way to link to multiple work books without manually linking them each time?

View 9 Replies View Related

Links To External Workbooks And Server Drive Selected?

Aug 7, 2013

I have a workbook that is being used by many individuals. Within it contains links to an external workbook on a server. Currently the links in the workbook map the server to drive "T".

If a different user maps the same server to another drive letter, I assume these links need to be updated with the drive letter he/she is using for that server?

View 1 Replies View Related

Open External File

Mar 7, 2008

I have a userform which saves project details....

Part of the makeup of the userform is a label control (label11) which can store a filepath for an external file (word doc, PDF etc)

How can i open this external file? (the filepath is stored as the caption)

View 9 Replies View Related

How To Manage New Year File Name Change When Linked To External Workbooks?

Nov 12, 2009

I have a set up a workbook which is linked to numerous other workbooks to provide a summary of information in one location.

However, when we reach April the names of all the linked worksheets will change from 'name 09 - 10' to 'name 10 - 11'.

What is the best way of handling this transition, will I have to manually change all of the links?

I have attached a much simplified example, unfortunately I cannot post the original due to sensitive data.

Apologies if the explanation isnt clear enough, let me know and I'll give further detail.

View 2 Replies View Related

Macro To Open External Program?

Oct 18, 2012

I've only used VBA to expedite Excel processes, so this is my first exploit into using it for something else. So there's a radio program I enjoy listening to. It's not local, so I have to stream it online. I got a job recently, and I can no longer listen to the program during the day (my job doesn't allow streaming audio). So basically to hear the program, I have an internet explorer add-on called freecorder that records streaming audio. Basically what I've done till now is start recording the streaming radio before work and then stop recording when I get home. That creates quite a large file, so I'd like to set up a macro that does the following:

1) Open internet explorer at noon
2) Go the website from which the radio station streams
3) Click the button that starts freecorder recording
4) At 3 o'clock click the button that stops recording

View 1 Replies View Related

Close All Workbooks In Other Folder

Dec 22, 2009

I have several workbooks in a make your day folder categorized under several sub folders. Each workbook has a macro that calls the following macro:

View 2 Replies View Related

Close Workbooks In Other Instances

Feb 5, 2010

I have one main workbook that, when opened, opens three other workbooks each in its own instance of Excel. I'd like to know how to close all three of these upon closing this main workbook.

View 2 Replies View Related

Close Multiple Workbooks

Feb 16, 2007

How can I close the currentmonthend AND previousmonthend workbooks in the following code, but leave workbook "MoEnd Compare" open? I'd like to do some additional comparisons with the "MoEnd Compare" file. I tried the code below to close those two workbooks, but it is not working.

Sub check_month_end()
Dim currentmonthend
Dim previousmonthend
Dim project_current
Dim ptcurrent
Dim yearcurrent
Dim project_previous
Dim ptprevious
Dim yearprevious
Dim r As Integer
Dim c As Integer
Dim l As Integer
MsgBox "This will check project type and year on current and last period month end report."
currentmonthend = Application. GetOpenFilename("Excel Files (*.xls),*.xls", , "Select CURRENT Month End Report?")
previousmonthend = Application.GetOpenFilename("Excel Files (*.xls),*.xls", , "Select PREVIOUS Month End Report?").......................

View 2 Replies View Related

Creating External Reference With Variable?

Feb 27, 2014

I'm wondering if there's any way to put a variable for a cell address in an external reference formula. Basically, I'm creating an abridged report of customer data that takes a single customer's info from 2 other workbooks on a networked drive and compiles the chosen cell data into one worksheet summary of their info. The base external reference formula looks like this:

='F:Projects[CustomerDB.xls]Sheet1'!VariableCellGoesHere

I want to know if there's a way I can make the formula use a variable cell address that I can just type into another cell to tell it which row I need to grab info from. Generally, all of the customer data I need is spanned across multiple columns in one single row. The formula above appears multiple times in the sheet I'm trying to make. The first is for "Name", the next is for "Address", next is "Phone Number", etc. So for instance, if I want customer data from the main spreadsheet and that customer's info is on row 355, my first few formulas are:

='F:Projects[ProjectDB.xls]Sheet1'!$A$355
='F:Projects[ProjectDB.xls]Sheet1'!$B$355
='F:Projects[ProjectDB.xls]Sheet1'!$C$355

Is there a way I can maybe have a designated cell where I just enter the row number I need (e.g. 481) so the formula sees that number and plugs it into the cell reference above resulting in the formulas adjusting themselves to ='F:Projects[ProjectDB.xls]Sheet1'!$A$481?

View 9 Replies View Related

Value Of A Cell In An External And Variable Workbook

Mar 16, 2008

I need to create a formula or code which will return the value of cell d16 from an external and unopened workbook, where that external workbook's file name, directory and sheet names are provided within cells (able to be updated) of the current workbook. I have downloaded the add-in for INDIRECT.EXT but either being unfamiliar with this function or that I'm barking up the wrong tree all I'm getting is #REF!

And to add to my problem, I was hoping to use this formula / code within an excel table embedded in a word document.

View 9 Replies View Related

Get The Modified And Open Date Of An External Workbook

Sep 16, 2009

I have a list that show file names and when the necessary works on these files were completed, but the powers that be want more. I have been asked to add two more columns, one showing when the file was last opened and the other when it was last modified.

Is it possible to do this through VBA without having to open the files that are listed? If so I will run the macro when the workbook is first opened.

View 10 Replies View Related

Must Open External File To Link Formula

Oct 26, 2009

We're using SUMIF and it won't work unless the external excel file is open.

This is the formula we're using:

View 7 Replies View Related

Reading External File On Workbook Open

Jun 19, 2006

when i run this code under a button on a sheet it works fine. but i would like to run when the workbook opens (but i get an error message

On Error Resume Next
Application. ScreenUpdating = False
Dim wb As Workbook
Dim ws As Worksheet
'create new work order number...
Set wb = Application.Workbooks.Open("c: empex_ExternalOrderNumber.xls")
Set ws = Worksheets("NumberIncrement")
'get new WO number from numberincrement.xls
If Err.Number <> 0 Then
MsgBox Err.Description & "...help"
Else
mynewnumber = ws. Range("b1").Value
Range("g5").Value = mynewnumber
wb.Close
End If

Application.ScreenUpdating = True

View 2 Replies View Related

Close All Workbooks Except For The Main Workbook

Jan 5, 2009

Is there anyway to change the following code so that it will save and close all workbooks except the one that has this code?

View 3 Replies View Related

VBA Code To Close Inactive Workbooks

Sep 7, 2009

I tried to use Workbooks("Inactivebookname.xlsm").Close False
and many variations thereof, but I simply cannot close this workbook when currently another workbook is active.

I have no problem in closing an active workbook with
ActiveWorkbook.Close

View 9 Replies View Related







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