Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Way to only import new files?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shikamikamoomoo - 23 Mar 2006 17:32 GMT
Below is code that I found on a site by Ron De Bruin. It seems to wor
well for what I am asking it to, but I am curious if there is a way t
speed it up. The folder that it is pulling information from has severa
hundred files and it takes a great deal of time. I'm not sure if perhap
I do not have the right code for this type of process or if there i
anything I can do other than sit and wait for it to update. Or I wa
wondering if there is a way to modify it to only update new files an
paste the information at the next available blank line.... Help i
appreciated. Thanks!

Sub Example1()
Dim basebook As Workbook
Dim mybook As Workbook
Dim rnum As Long
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String
Dim Cnum As Integer
Dim cell As Range

SaveDriveDir = CurDir
MyPath = "C:\Documents and Settings...."
ChDrive MyPath
ChDir MyPath

FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Set basebook = ThisWorkbook
'clear all cells on the first sheet
'basebook.Worksheets(1).Cells.Clear

rnum = 2

Do While FNames <> ""
Set mybook = Workbooks.Open(FNames)

Cnum = 1
For Each cell In mybook.Worksheets(1).Range("D4,I4,C6,D6")
basebook.Worksheets(1).Cells(rnum, Cnum).Value = cell.Value
Cnum = Cnum + 1
Next cell

mybook.Close False
rnum = rnum + 1
FNames = Dir()
Loop

ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = False
End Su
Ron de Bruin - 23 Mar 2006 22:13 GMT
Hi shikamikamoomoo

I will make a example for you (also for the site)
Tomorrow or Saterday I post back (Busy on this moment)

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> Below is code that I found on a site by Ron De Bruin. It seems to work
> well for what I am asking it to, but I am curious if there is a way to
[quoted text clipped - 54 lines]
> Application.ScreenUpdating = False
> End Sub
shikamikamoomoo - 23 Mar 2006 22:52 GMT
Thank you so much!!! Greatly appreciated.  :)

Signature

shikamikamoomoo

Ron de Bruin - 24 Mar 2006 18:50 GMT
Hi shikamikamoomoo

Here is one to test for you
Will finish it tomorrow and add it to the webpage

Copy the function also in the module

Sub Test_More_Areas()
   Dim basebook As Workbook
   Dim mybook As Workbook
   Dim rnum As Long
   Dim FNames As String
   Dim MyPath As String
   Dim SaveDriveDir As String
   Dim Cnum As Integer
   Dim cell As Range

   SaveDriveDir = CurDir
   MyPath = "C:\Data"
   ChDrive MyPath
   ChDir MyPath

   FNames = Dir("*.xls")
   If Len(FNames) = 0 Then
       MsgBox "No files in the Directory"
       ChDrive SaveDriveDir
       ChDir SaveDriveDir
       Exit Sub
   End If

   Application.ScreenUpdating = False
   Set basebook = ThisWorkbook

   Do While FNames <> ""

       If IsError(Application.Match(FNames, _
                                    basebook.Worksheets(1).Columns("A"), 0)) Then
           rnum = LastRow(basebook.Worksheets(1)) + 1
           Set mybook = Workbooks.Open(FNames)

           ' This will add the workbook name in column A if you want
           basebook.Worksheets(1).Cells(rnum, "A").Value = mybook.Name

           ' Copy the cell values from each cell in one row starting in column B
           Cnum = 2
           For Each cell In mybook.Worksheets(1).Range("A2,A3,C2,C3,E2,E3")
               basebook.Worksheets(1).Cells(rnum, Cnum).Value = cell.Value
               Cnum = Cnum + 1
           Next cell
           mybook.Close False
       End If
       FNames = Dir()
   Loop

   ChDrive SaveDriveDir
   ChDir SaveDriveDir
   Application.ScreenUpdating = True
End Sub

Function LastRow(sh As Worksheet)
   On Error Resume Next
   LastRow = sh.Cells.Find(What:="*", _
                           After:=sh.Range("A1"), _
                           Lookat:=xlPart, _
                           LookIn:=xlFormulas, _
                           SearchOrder:=xlByRows, _
                           SearchDirection:=xlPrevious, _
                           MatchCase:=False).Row
   On Error GoTo 0
End Function

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> Thank you so much!!! Greatly appreciated.  :)
shikamikamoomoo - 25 Mar 2006 00:21 GMT
hmmm...perhaps I am not copying this into the right location.  I copied
the entire code into worksheet 1 and then the Function section into
module 1....is this right?  It seems like it does something....but I'm
not sure what.  It does not copy anything into the file.

Signature

shikamikamoomoo

Ron de Bruin - 25 Mar 2006 00:46 GMT
Copy both in a normal module(not a sheet module)

Change the path to yours

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> hmmm...perhaps I am not copying this into the right location.  I copied
> the entire code into worksheet 1 and then the Function section into
> module 1....is this right?  It seems like it does something....but I'm
> not sure what.  It does not copy anything into the file.
Ron de Bruin - 25 Mar 2006 13:29 GMT
I have update the site
http://www.rondebruin.nl/copy3.htm#new

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> Hi shikamikamoomoo
>
[quoted text clipped - 59 lines]
>> Application.ScreenUpdating = False
>> End Sub
shikamikamoomoo - 26 Mar 2006 08:09 GMT
I'm not sure what I am doing wrong, but I cannot get this to copy
anything over.  I've tried copying the entire code including the
Function into Module 1.  But when I run it nothing happens.  Do I need
this code plus the original? I changed the path to the right location
and I do not get any errors.

Signature

shikamikamoomoo

Ron de Bruin - 26 Mar 2006 08:55 GMT
Send me your test file with the code private and I will see where you went wrong

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> I'm not sure what I am doing wrong, but I cannot get this to copy
> anything over.  I've tried copying the entire code including the
> Function into Module 1.  But when I run it nothing happens.  Do I need
> this code plus the original? I changed the path to the right location
> and I do not get any errors.
shikamikamoomoo - 27 Mar 2006 17:45 GMT
Sent a copy of the file....thanks for your help :)

Signature

shikamikamoomoo

Ron de Bruin - 27 Mar 2006 18:20 GMT
Nothing in my Inbox ?

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> Sent a copy of the file....thanks for your help :)
shikamikamoomoo - 27 Mar 2006 19:37 GMT
I sent it to the address on your site and it bounced back saying that
the server refused it.  Spam block?

Signature

shikamikamoomoo

Ron de Bruin - 27 Mar 2006 19:57 GMT
Strange

Zip it and try again

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> I sent it to the address on your site and it bounced back saying that
> the server refused it.  Spam block?
shikamikamoomoo - 28 Mar 2006 00:09 GMT
Sent it again, this time the file is zipped.  :)

Signature

shikamikamoomoo

Ron de Bruin - 28 Mar 2006 05:18 GMT
Have you used the correct address
rondebruin@kabelfoon.nl

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> Sent it again, this time the file is zipped.  :)
shikamikamoomoo - 28 Mar 2006 17:18 GMT
Yes I'm sure that is the address that I used, same one that is on your
Excel Help site.  I sent it again straight from here so this time it is
definately the address that I am using.

Signature

shikamikamoomoo

shikamikamoomoo - 28 Mar 2006 17:20 GMT
The file will be coming from jennyb@venturedata.com (in case it is
filtered in with junk mail)

Signature

shikamikamoomoo

Ron de Bruin - 28 Mar 2006 17:40 GMT
I send you a private mail

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> The file will be coming from jennyb@venturedata.com (in case it is
> filtered in with junk mail)
shikamikamoomoo - 28 Mar 2006 18:19 GMT
Replied to the email.....let me know if you still do not hear anything.
If this doesn't work, I'll try to send it from a different email address
later this evening.

Signature

shikamikamoomoo

Ron de Bruin - 28 Mar 2006 20:11 GMT
Nothing

How big is the file ?

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> Replied to the email.....let me know if you still do not hear anything.
> If this doesn't work, I'll try to send it from a different email address
> later this evening.
shikamikamoomoo - 28 Mar 2006 20:51 GMT
52.3 KB -

I will send it through my other email later this evening....other than
that I'm not sure what to do.

Signature

shikamikamoomoo

Ron de Bruin - 28 Mar 2006 21:12 GMT
Very strange

I hope I see it <g>
Late in the evening here so maybe I reply tomorrow

Signature

Regards Ron de Bruin
http://www.rondebruin.nl

> 52.3 KB -
>
> I will send it through my other email later this evening....other than
> that I'm not sure what to do.
shikamikamoomoo - 29 Mar 2006 17:10 GMT
My apologies, I did not get a chance to send that off last night.  I'm
assuming you still have not received the previous emails that I sent (I
haven't seen a bounce back message yet).  We'll have to put this on hold
one more day and I'll send it off tonight.  Thanks for your patience.

Signature

shikamikamoomoo

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.