Conditional import of Excel sheets

Hi, maybe someone can help me with the following: on a weekly basis I
need to import 3 Excel files into an existing empty table (I run a
delete query on this table before the import). The Excel files are
stored in the same folder every week. Each file has a field showing
[Current Year/Week No]. The three files show the current week for
this
year, previous year and the year before the previous year. How can
you
instruct MS Access (2003) to look up this field and to import only
the
approrpiate files (i.e. the files that refer to the reporting week)? I
do have
a calender function from which the user can select the date (and
deduct
the 2 previous dates). I should be able to incorporate that into the
code
(with a little help...).
Any ideas? Let me know if you need more info, thanks a million, Paul

0
Paul
10/24/2007 12:13:15 PM
access 16762 articles. 3 followers. Follow

9 Replies
996 Views

Similar Articles

[PageSpeed] 27

Are there more than 3 files in the folder?  Is your problem finding the 
correct files among hundreds, or just reading the year/week value?  Or both?

"Paul" wrote:

> Hi, maybe someone can help me with the following: on a weekly basis I
> need to import 3 Excel files into an existing empty table (I run a
> delete query on this table before the import). The Excel files are
> stored in the same folder every week. Each file has a field showing
> [Current Year/Week No]. The three files show the current week for
> this
> year, previous year and the year before the previous year. How can
> you
> instruct MS Access (2003) to look up this field and to import only
> the
> approrpiate files (i.e. the files that refer to the reporting week)? I
> do have
> a calender function from which the user can select the date (and
> deduct
> the 2 previous dates). I should be able to incorporate that into the
> code
> (with a little help...).
> Any ideas? Let me know if you need more info, thanks a million, Paul
> 
> 
0
Utf
10/24/2007 1:40:02 PM
On Oct 24, 3:40 pm, Lance <La...@discussions.microsoft.com> wrote:
> Are there more than 3 files in the folder?  Is your problem finding the
> correct files among hundreds, or just reading the year/week value?  Or both?

Hi Lance, thanks for your reply. The folder will be filled with a
total of 8 files every week. They are all appended into separate
tables (apart from these 3). I intend to clean up this folder once
every while, so we're talking about maybe 50 files max.

0
Paul
10/25/2007 7:53:51 AM
OK try this out, you may need to add some references for ADO and microsoft 
scripting.  Also, it always treats the excel spreadsheet as having the first 
line as field names, regardless of what you put in.  It seems to add 1 to 
your cell reference line.  Sorry, I didn't have the time to figure that out.. 
but would love to know if you do.

I ran it through a group of 10 excel worksheets in a folder and looked for 
the word "ODD" in cell A2 ( entered in code as A1, see above for error ) and 
it worked well enough.  





Sub check_excel_files()
   Dim fsoSysObj As Scripting.FileSystemObject
   Dim fdrFolder As Scripting.Folder
   Dim filFile As Scripting.File
   Dim strPath As String
   
   strPath = "C:\Projects\LIBRARY"
   Set fsoSysObj = New Scripting.FileSystemObject
   Set fdrFolder = fsoSysObj.GetFolder(strPath)
   
   For Each filFile In fdrFolder.Files
      If filFile.Type = "Microsoft Excel Worksheet" Then
      
      '*****************************************************
      '* INSERT CODE TO CHECK EXCEL VALUE HERE
      '*****************************************************
         If x_value_from_excel(filFile.Path, "Sheet1", "A", 1, 0) = "ODD" Then
            MsgBox filFile.Path & " is an odd numbered file."
         End If
      '******************************************************
      
      End If
   Next filFile
   
   
   
   
   Set fsoSysObj = Nothing
   Set fdrFolder = Nothing
   
End Sub

Function x_value_from_excel(inFile As String, inWorkSheet As String, inCol 
As String, inRow As Integer, inFirstRowHasNames As Integer)
   
   On Error GoTo handler
   Dim cn As ADODB.Connection
   Dim rs As ADODB.Recordset
   
   Set cn = New ADODB.Connection
   Set rs = New ADODB.Recordset
   
   strquery = "SELECT * FROM [" & inWorkSheet & "$" & inCol & inRow & ":" & 
inCol & inRow + 1 & "]"
   
   With cn
      .Provider = "MSDASQL"
      .ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" & 
inFile & "; ReadOnly=False;FirstRowHasNames=" & inFirstRowHasNames & ";"
      .Open
   End With
   
   Call rs.Open(strquery, cn)
   x_value_from_excel = rs(0)
   
  cn.Close
  Exit Function
handler:
  MsgBox Err.Description
  x_value_from_excel = "ERROR"
End Function
0
Utf
10/25/2007 2:02:01 PM
I have to say, Lance, this goes somewhat over my head...to put it
mildly. I do appreciate your time on this, though, but somehow I feel
this is getting too complicated (for me anyway). I have been thinking
this over (thanks to you and another expert) and I figured that the
files I do not need all have in common that they were downloaded on a
different date than the files I do need, which will always be
downloaded the same day. Could I use the date criteria somehow as a
condition to import or not? If possible, that seems easier to me.
Thanks again for your time. Paul

0
Paul
10/26/2007 1:50:28 PM
That's something I thought about putting in the script I posted before.  And 
it's certainly doable, but you'll still have to loop through files and 
extract the datecreated value from it.  But that would allow you to skip 
reading the excel file.

But let's step back from that for a second, maybe there's an easier solution.

How are these files generated?  Is it an automatic machine generated file 
with a machine generated name?  If so is there some pattern to the naming 
convention being used?

If it's a human generated, is it possible to just have the file saved as the 
same name each time?



"Paul" wrote:

> I have to say, Lance, this goes somewhat over my head...to put it
> mildly. I do appreciate your time on this, though, but somehow I feel
> this is getting too complicated (for me anyway). I have been thinking
> this over (thanks to you and another expert) and I figured that the
> files I do not need all have in common that they were downloaded on a
> different date than the files I do need, which will always be
> downloaded the same day. Could I use the date criteria somehow as a
> condition to import or not? If possible, that seems easier to me.
> Thanks again for your time. Paul
> 
> 
0
Utf
10/26/2007 2:10:01 PM
The files are downloaded from an external source and the naming logic
includes their internal request number, which makes it impossible to
foresee. The files are manually uploaded and then saved to the
directory, but to install a naming convention there woudl be error
prone, because I'm not the only one that runs the reports (in fact, I
designed it so that other could run it as well) and I am the only one
with a little Access knowledge.

0
Paul
10/29/2007 10:16:34 AM
If you go with the "static file names" it wouldn't be difficult to check if 
the files have current data before processing them.. for what that's worth.

The only other options I see is to make a form which prompts users to choose 
the files they upload.. and then make running that form part of the file 
creation process.  A lot less automated though.

"Paul" wrote:

> The files are downloaded from an external source and the naming logic
> includes their internal request number, which makes it impossible to
> foresee. The files are manually uploaded and then saved to the
> directory, but to install a naming convention there woudl be error
> prone, because I'm not the only one that runs the reports (in fact, I
> designed it so that other could run it as well) and I am the only one
> with a little Access knowledge.
> 
> 
0
Utf
10/29/2007 2:32:01 PM
So maybe I can let the user choose himself and th=E8n do a date
validation. That would enforce awareness, prevent mistakes and
overall, it will not stall tohe process too much. Thanks, Lance, for
your ideas and time. Much appreciated, Paul

0
Paul
10/31/2007 8:34:46 AM
Paul:
i don't understand your RE: to my ? about an Epson pinter color II model 
P880A: it was giving to me and the first time printed OK, but after that 
prints # and crazy characters as long as there is paper in the printer.tia 

0
hoolio
11/2/2007 1:20:30 PM
Reply:

Similar Artilces:

Today Conditional Format
I have a column which calculated a date based on 3 working days from a date input into a diff column. What I want to do I have the calculated date appear bold if that date has passed based on the current date. For example if I input 01/08/11 the next column calculates 04/08/11 (3 working days). I want the caluclated date to appear bold when I open the spreadsheet on the 05/08/11 ro show the calculated date has passed. I can use conditional formatting but can't get the syntax right Regards Andy Win XP Pro Office 2010 Andy Roberts presented the following explanation : > I ha...

Quickbooks Import into RMS
Our client called RMS tech support on the phone and was told that RMS can only export information into quickbooks, but can not import any information. Is that correct ? I thought that you can do both, import and export ? Any thoughts ? Thanks. -- GCI GCI, RMS will do a limited import from QB. After you've setup QuickBooks as your accounting program in Manager | File | Configuration | Accounting tab, then go to Manager | Utilities | Import QuickBooks | select what you want to import -- * Get Secure! - www.microsoft.com/security You must be using Outlook Express or some other typ...

problem copying excel wroksheets
Hi all, when i try to create a copy of a worksheet from one workbook to another i get the following error message :- Microsoft Visual Basic file not found: 'C:\DOCUME~1\adonafee\LOCALS~1\Temp\VB37.tmp' can anyone help me out with this please???? Maybe cleaning up your temp folder will help. close excel windows start button|run %temp% Delete all those files and folders. It may be best to do this right after you reboot your pc, so that no other programs are running that need any of these files. == If that doesn't help, try disabling your antivirus software (just temporarily) ...

That I do I cannot open to archives in Word nor Excel?
Would you please use this large open space to give us a better idea of your problem? -- JoAnn Paules MVP Microsoft [Publisher] ~~~~~ How to ask a question http://support.microsoft.com/KB/555375 "Antonio" <Antonio@discussions.microsoft.com> wrote in message news:EED7F92A-D1E4-40AF-98ED-2F6107301E4B@microsoft.com... > ...

when I open excel file,changes was undid-excel 2007, compatibility
I have a file that was made in excel 2007 working in compatibility mode and when I change format in some cell (for example font size), then I save changes and after reopen this fiel the changes was undid. Can some help me? Sorry for my english isn't very well -- thanks Pedro ...

Two Condition Vlookup?
I am currently trying to create a function that searches through an array for two exact column values which allows me to retrieve a third column value. For example: Type of Fruit Date Packaged Amount of Fruit Apples June 100 Oranges June 50 Apples July 75 Grapes July 50 In this example, I would be looking to retrieve the Amount of Fruit (Apples) that was packaged in July. I would be putt...

Import from Excel
I am running Outlook 2002 and I am trying to import addresses from excel. The addresses are in traditional excel form...A1:name, B1:address, C1:city, etc. It has worked, however, when I import each column under name, address, city, etc., each cell is getting listed under a new contact????? Does anyone know how I can get each address under ONE contact in outlook???? ...

Excel Queries using Access data
Im trying to create a query from within Excel. When I select new database query and select a database which has no securtiy login/password, no problem, works fine. However, when I try to source the data from a database which I have created using user logins/passwords it says that I do not have admin privilages to use the database even though I am putting in the correct login/username in the popup window? Please can anyone help? I've had limited experience with this sort of thing but I've always had to strip out the protection on the Access Database and create a copy before suc...

Excel To money
i have a ledger for my checking account in excel that i wish to convert to money format how do i do this ? In microsoft.public.money, WStoreyII wrote: >i have a ledger for my checking account in excel that i wish to convert to >money format how do i do this ? > See http://xl2qif.chez.tiscali.fr/xl2qif_en.php ...

Query condition by date range
I'm trying to create a query to base a report from. I need it to return records within a date range that needs to be specified, as in specifying the beginning date and having the current date as the end date. A field is included in the query that has listed dates in the format mm/dd/yyyy. How would I write the criteria? I have part of it ready - [Please enter starting date:] . I know that's how you get the little question window. On Tue, 4 Dec 2007 14:51:00 -0800, silva wrote: > I'm trying to create a query to base a report from. I need it to return > records within a...

Is there any way to do a rose diagram in Excel?
Is there a plugin or some way to plot a rose diagram in Excel 2003? In article <F6F21C0C-9297-4939-9153-C2AAA85F0A54@microsoft.com>, Jed@discussions.microsoft.com says... > Is there a plugin or some way to plot a rose diagram in Excel 2003? > Check the google.com archives of the XL newsgroups for several leads. Start with http://groups.google.com/advanced_group_search?q=group:*Excel* -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions ...

Short Key for Selecting Tab Sheets?
Excel 2000 ... Is there a short-key for jumping TabSheet to TabSheet instead of using the mouse? ... Thanks ... Kha Ken, Use Ctrl+PageUp and Ctrl+PageDown -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Ken" <anonymous@discussions.microsoft.com> wrote in message news:1fb401c3e057$900fff90$a401280a@phx.gbl... > Excel 2000 ... Is there a short-key for jumping TabSheet > to TabSheet instead of using the mouse? ... Thanks ... Kha >-----Original Message----- >Ken, > >Use Ctrl+PageUp and Ctrl+PageDown &g...

2007 excel autofilter change back to 2003?
Is it possible to change the autofilter in excel 2007 back to the way excel 2003 worked? I see you have a response to one of your other posts -- in a different forum. jonnybrovo815 wrote: > > Is it possible to change the autofilter in excel 2007 back to the way excel > 2003 worked? -- Dave Peterson ...

Need help with conditional formula (Excel 97)
Can anyone give me the correct syntax for the following formula: if A1 is blank, and B1 is more than zero, then display B1, otherwise display nothing (blank cell) Thank you JD =IF(AND(A1="",B1>0),B1,"") Success! -- met vriendelijke groetjes "Jake D" <JakeD@djhtend.com> schreef in bericht news:crkto4lv30u7uujv27ek8okr0us5t9oj10@4ax.com... > Can anyone give me the correct syntax for the following formula: > > if A1 is blank, and B1 is more than zero, then display B1, otherwise > display nothing (blank cell) > > Thank you > > ...

See that important patch from the MS Corp.
--mnqbifzstjwnoqccp Content-Type: multipart/related; boundary="rbkkbifudezkn"; type="multipart/alternative" --rbkkbifudezkn Content-Type: multipart/alternative; boundary="vdsdrqruhwoiboko" --vdsdrqruhwoiboko Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft Consumer this is the latest version of security update, the "November 2003, Cumulative Patch" update which fixes all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express as well as three newly discovered vulnerabilities. Ins...

Conditional formatting if condition of an if statement is true and a string value is displayed
Dear Experts: I got a nested 'IF'-Formula in an excel cell that returns nothing if the condition is false. I would like to conditionally format this cell with grey shading if the condition is true and a string value is displayed. How can this be achieved using excel conditional formating functionality ? Help is much appreciated. Thank you very much in advance. Regards, Andreas Let's say your doing this conditional formatting in cell K17. In conditional formatting (xl2003) choose the FormulaIs: option and enter: =$K$17<>"" choose your formatt...

Problems with Excel 97 after installing Windows XP
Hello together I have the following problem with Excel 97 after installing Windows XP: When I want to change the options (menu extras options) excel 97 closes itself automatic without showing me the options. Has someone already had this problem and could solve it? If yes, please let me know what is wrong. Thanks in advance. Hi Darilenz, > When I want to change the options (menu extras options) > excel 97 closes itself automatic without showing me the > options. > Sounds like a known problem: http://support.microsoft.com/default.aspx?scid=kb;en-us;108032 (url all on o...

Import / Export #2
Running Vista Business Edition, Office 2007. 1. Microsoft web pages, for example http://support.microsoft.com/kb/290859 state that there is a menu item for "Import / Export" under the File menu, but it does not appear on my Outlook. Does anyone know where the menu item is and/or why it does not appear? TIA Andrew It could have been disabled or not installed by your corporate admin. -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.msoutlook.info/ Real World...

Conditional Field in Queries
Is there a way to make a field in a query conditional so that it only displays the value if the value is equal to something specifically set? Thanks. Nick Nick.Korynski@gmail.com wrote: > Is there a way to make a field in a query conditional so that it only > displays the value if the value is equal to something specifically > set? Thanks. > > Nick Explain "the value is equal to something specifically set". -- Rick Brandt, Microsoft Access MVP Email (as appropriate) to... RBrandt at Hunter dot com ...

Importing emails
I've recently transferred the files from my old computer to this new one, using Windows Easy Transfer via an external hard drive. My old computer was XP with Outlook Express 6. I have now imported my old emails into Live Mail and it has created a folder in storage area but when I click on it, the folder is empty! I've read some of the old postings and tried some of the recommendations, all to no avail. I've clicked on the little arrow on the side to expand the folder and also made sure that Show Storage folders is ticked but the folder is still empty. The f...

Excel VBA programmer needed
Programmer needed visual basic, in excel I own a bee removal company . I keep most my records and calcualtions in excel and I am looking for an excel specialist / vba programmer that can write code to simplify and speed up some of the time consuming tasks. Time is a factor for me, money is less of a factor. I imagine it would be around 80 hrs work. With probable future changes and or additions that would most likley arise. Example: Bee removal work can be divided into two parts, 1 exterminating a hive, and 2. removing the honey from the structure (from 5 to 300 lbs). The field rep exterm...

How do i use Conditional formatting for 3+ conditions ?
I have a text box in a report which highlights in colour current members in a list of past and present member names. I have six types of current members that I want to highlight, but with conditional formatting I can only use 3 conditions in the members [Type] field. I have tried [Type]="Full member" Or "Life member" but the "Or" doesn't work ! Is there a way to do this ? thanks .. Roger CF is limited to 3 contitions, but you can use OR in those expressions. If you set Condition1 to Expression, you can use: ([Type] = "Full member") Or (...

Help with Conditional formatting with Dates
Hi there, I have a spreadsheet in which I have to monitor various dates which are in different columns (i.e. (1) Date Tender Released, (2) Date Company Selected, (3) Date Draft Contract Forwarded, (4) Date Contract Signed etc...). Would if be possible to Conditional Format and have diffirent ROWs highlighted for each individual Contracts (I have 300 running contracts running) every time a date is filled in these different columns: Initial Step (1) = Yellow (Call for Tender released) Step (2) = Blue (Company Selected) Step (3) = Brown (Contract under Process) Step (4) = Green (Contract Si...

Export/Importing Addressbook & Emails
How do I export emails and address book from OE running on a laptop with Win Me to a desktop with Win XP and Outlook. Is there a step-by-step guide somewhere? Thanks Can't be done. Outlook and OE must be on the same partition to do any importing between them. Go to an OE group and ask how to import your data from one installation of OE to another. Once you do, it is simple to use Outlook's Import Wizard to import from OE into Outlook. This is a group to support Outlook from the Office group of programs. Outlook Express is a part of Internet Explorer and is a quite different pr...

DSOFramer, MFC and Excel
I am developing an application that has a DSOFramer control in a view. The problem is, the control tends to deactivate and the cells will show only after you have resized the form or have hovered the mouse over the cells and scrollbar. I tried setting the FrameHookPolicy to 1 (dsoSetOnFirstOpen) but still.... The funny thing is that it works perfectly in a WinForm(c#) but still has problems updating. I have tried activating it in the OnPaint and ApplicationActivate events but still to no avail. ...