Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-26-2017, 11:06 AM
OfficeAssociate99 OfficeAssociate99 is offline VBA to automatically pull data from other excel documents Windows 7 64bit VBA to automatically pull data from other excel documents Office 2010 64bit
Novice
VBA to automatically pull data from other excel documents
 
Join Date: May 2017
Posts: 19
OfficeAssociate99 is on a distinguished road
Default VBA to automatically pull data from other excel documents

Hi,
I'm trying to automate the process of pulling data from a certain range (not all data) from around 6-7 other excel files into one master document. It would be great if I could filter the documents based on their title (i.e. they are all dated, so if I set it so that the program would search for the current date in all the titles, and pull very specific data sets into the master copy). All the documents are formatted using the same template.


Any help would be appreciated, as I am a n00b when it comes to programming.
Thanks.
Reply With Quote
  #2  
Old 05-29-2017, 09:15 AM
BobBridges's Avatar
BobBridges BobBridges is offline VBA to automatically pull data from other excel documents Windows 7 64bit VBA to automatically pull data from other excel documents Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

I do this fairly often, and have developed some regular functions and classes to help. The general idea is that I use the FileSystemObject to run through all the files in a folder, and a Regular-Expression object to determine which filenames match the desired pattern. Does that tell you what you need to now, or do you need more information on one or both?
Reply With Quote
  #3  
Old 05-29-2017, 10:43 AM
OfficeAssociate99 OfficeAssociate99 is offline VBA to automatically pull data from other excel documents Windows 7 64bit VBA to automatically pull data from other excel documents Office 2010 64bit
Novice
VBA to automatically pull data from other excel documents
 
Join Date: May 2017
Posts: 19
OfficeAssociate99 is on a distinguished road
Default

Quote:
Originally Posted by BobBridges View Post
I do this fairly often, and have developed some regular functions and classes to help. The general idea is that I use the FileSystemObject to run through all the files in a folder, and a Regular-Expression object to determine which filenames match the desired pattern. Does that tell you what you need to now, or do you need more information on one or both?
I have a little bit better of an idea. I'm more or less doing this from scratch, as I have limited working knowledge of VBA and coding related to that. Any additional details on either of items you mentioned would be great.
Reply With Quote
  #4  
Old 05-29-2017, 09:46 PM
BobBridges's Avatar
BobBridges BobBridges is offline VBA to automatically pull data from other excel documents Windows 7 64bit VBA to automatically pull data from other excel documents Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Most important, here's the link for the FileSystemObject and here's the one for the regular-expression object. However I can go a little further than that.

Here's some sample code where I use the FSO to look through the files in a folder and pick out the ones I want:
Code:
' Create the FileSystemObject and get the desired folder.
set ofs=CreateObject("Scripting.FileSystemObject")
if not ofs.folderexists(fnpIP) then abend "I can't find a folder named " & fnpIP & "!"
set ofo=ofs.getfolder(fnpIP)

' Look at each file in the folder and decide whether I want it.
for each ofi in ofo.files
  select case ofi.name
    case "Detroit.xlsm": bmch=True
    case "Chicago.xlsx": bmch=True
    case "Marywether.txt": bmch=True
    case else: bmch=False
    end select
  If bmch then
    ...process your file
    end if
  next ofi
This assumes that you want specific filenames. If you want a certain pattern of filenames, you can set up a RegExp "pattern" describing a filename that, for example, starts with one of three specified city names, then contains a date in ANSI format, and ends with "gener.xlsm". The run each filename past that RegExp pattern and use the ones that match and whose date is within the past 90 days. But regular expressions, while they're extremely flexible and powerful, are correspondingly complicated; we should talk about them in a separate thread.

Oh, by the way, the above code is not tested; I threw together the basic statements, but I don't promise there are no syntax errors. Should get you started though.

Last edited by BobBridges; 05-29-2017 at 09:47 PM. Reason: PS
Reply With Quote
  #5  
Old 05-30-2017, 12:22 PM
OfficeAssociate99 OfficeAssociate99 is offline VBA to automatically pull data from other excel documents Windows 7 64bit VBA to automatically pull data from other excel documents Office 2010 64bit
Novice
VBA to automatically pull data from other excel documents
 
Join Date: May 2017
Posts: 19
OfficeAssociate99 is on a distinguished road
Default

Quote:
Originally Posted by BobBridges View Post
Most important, here's the link for the FileSystemObject and here's the one for the regular-expression object. However I can go a little further than that.

Here's some sample code where I use the FSO to look through the files in a folder and pick out the ones I want:
Code:
' Create the FileSystemObject and get the desired folder.
set ofs=CreateObject("Scripting.FileSystemObject")
if not ofs.folderexists(fnpIP) then abend "I can't find a folder named " & fnpIP & "!"
set ofo=ofs.getfolder(fnpIP)
 
' Look at each file in the folder and decide whether I want it.
for each ofi in ofo.files
  select case ofi.name
    case "Detroit.xlsm": bmch=True
    case "Chicago.xlsx": bmch=True
    case "Marywether.txt": bmch=True
    case else: bmch=False
    end select
  If bmch then
    ...process your file
    end if
  next ofi
This assumes that you want specific filenames. If you want a certain pattern of filenames, you can set up a RegExp "pattern" describing a filename that, for example, starts with one of three specified city names, then contains a date in ANSI format, and ends with "gener.xlsm". The run each filename past that RegExp pattern and use the ones that match and whose date is within the past 90 days. But regular expressions, while they're extremely flexible and powerful, are correspondingly complicated; we should talk about them in a separate thread.

Oh, by the way, the above code is not tested; I threw together the basic statements, but I don't promise there are no syntax errors. Should get you started though.
Thanks, you've been very helpful. I'll try working through it.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to automatically pull data from other excel documents Using Excel data to automatically make Word documents Vincent Mail Merge 9 01-04-2021 03:05 PM
Pull data from Excel to Powerpoint (not dynamically) Terri11130 PowerPoint 1 08-25-2015 12:17 PM
How to get project to automatically pull in task dates? Moe Szylak Project 2 04-26-2012 12:37 PM
Excel VBA: Pull data from web tinfanide Excel Programming 0 12-09-2011 02:11 AM
VBA to automatically pull data from other excel documents Old Excel Document folder automatically created in My Documents slickcondo Office 6 07-13-2011 02:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft