PC Review


Reply
Thread Tools Rate Thread

How to code it in macro?

 
 
Eric
Guest
Posts: n/a
 
      22nd May 2010
Does anyone have any suggestions on how to code it in macro?

There is a list of files under column A, I would like to create a macro to
open - updating all links - save - close each file one by one for each file
from A2 to A20. There is one condition to process each file, for example;

The following files will not be processed until the last updated for this
file C:\documents\A.xls is today, then open - updating all links - save -
close following files,

C:\documents\A1.xls in cell A2
C:\documents\A2.xls in cell A3
C:\documents\A3.xls in cell A4

The following files will not be processed until the last updated for this
file C:\documents\B.xls is today, then open - updating all links - save -
close following files,

C:\documents\B1.xls in cell A5
C:\documents\B2.xls in cell A6
C:\documents\B3.xls in cell A7

The following files will not be processed until the last updated for this
file C:\documents\C.xls is today, then open - updating all links - save -
close following files,

C:\documents\C1.xls in cell A8
C:\documents\C2.xls in cell A9
C:\documents\C3.xls in cell A10
....

Does anyone have any suggestions on how to code it in macro?
Thanks in advance for any suggestions
Eric
 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      24th May 2010
See if this works for you.

Option Explicit

Sub Test()
Dim aWS As Excel.Worksheet
Dim myRange As Excel.Range
Dim myWB As Excel.Workbook
Dim r As Excel.Range

Set aWS = ActiveSheet
Set myRange = aWS.Range("A2:A10")

For Each r In myRange
Set myWB = Workbooks.Open(r.Text, UpdateLinks:=True)
myWB.Close savechanges:=True
Set myWB = Nothing
Next r

End Sub


--
HTH,

Barb Reinhardt



"Eric" wrote:

> Does anyone have any suggestions on how to code it in macro?
>
> There is a list of files under column A, I would like to create a macro to
> open - updating all links - save - close each file one by one for each file
> from A2 to A20. There is one condition to process each file, for example;
>
> The following files will not be processed until the last updated for this
> file C:\documents\A.xls is today, then open - updating all links - save -
> close following files,
>
> C:\documents\A1.xls in cell A2
> C:\documents\A2.xls in cell A3
> C:\documents\A3.xls in cell A4
>
> The following files will not be processed until the last updated for this
> file C:\documents\B.xls is today, then open - updating all links - save -
> close following files,
>
> C:\documents\B1.xls in cell A5
> C:\documents\B2.xls in cell A6
> C:\documents\B3.xls in cell A7
>
> The following files will not be processed until the last updated for this
> file C:\documents\C.xls is today, then open - updating all links - save -
> close following files,
>
> C:\documents\C1.xls in cell A8
> C:\documents\C2.xls in cell A9
> C:\documents\C3.xls in cell A10
> ...
>
> Does anyone have any suggestions on how to code it in macro?
> Thanks in advance for any suggestions
> Eric

 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      24th May 2010
Thank you very much for suggestions
The condition to hold processing the files is missing, for example, if the
last updated for this file C:\documents\B.xls is yesterday, then please hold
the following lists for processing:

C:\documents\B1.xls in cell A5
C:\documents\B2.xls in cell A6
C:\documents\B3.xls in cell A7

Do you have any suggestions on how to add this condition in coding?
I get no idea on how to do it,
Please help
Thank you very much for any suggestions
Eric


"Barb Reinhardt" wrote:

> See if this works for you.
>
> Option Explicit
>
> Sub Test()
> Dim aWS As Excel.Worksheet
> Dim myRange As Excel.Range
> Dim myWB As Excel.Workbook
> Dim r As Excel.Range
>
> Set aWS = ActiveSheet
> Set myRange = aWS.Range("A2:A10")
>
> For Each r In myRange
> Set myWB = Workbooks.Open(r.Text, UpdateLinks:=True)
> myWB.Close savechanges:=True
> Set myWB = Nothing
> Next r
>
> End Sub
>
>
> --
> HTH,
>
> Barb Reinhardt
>
>
>
> "Eric" wrote:
>
> > Does anyone have any suggestions on how to code it in macro?
> >
> > There is a list of files under column A, I would like to create a macro to
> > open - updating all links - save - close each file one by one for each file
> > from A2 to A20. There is one condition to process each file, for example;
> >
> > The following files will not be processed until the last updated for this
> > file C:\documents\A.xls is today, then open - updating all links - save -
> > close following files,
> >
> > C:\documents\A1.xls in cell A2
> > C:\documents\A2.xls in cell A3
> > C:\documents\A3.xls in cell A4
> >
> > The following files will not be processed until the last updated for this
> > file C:\documents\B.xls is today, then open - updating all links - save -
> > close following files,
> >
> > C:\documents\B1.xls in cell A5
> > C:\documents\B2.xls in cell A6
> > C:\documents\B3.xls in cell A7
> >
> > The following files will not be processed until the last updated for this
> > file C:\documents\C.xls is today, then open - updating all links - save -
> > close following files,
> >
> > C:\documents\C1.xls in cell A8
> > C:\documents\C2.xls in cell A9
> > C:\documents\C3.xls in cell A10
> > ...
> >
> > Does anyone have any suggestions on how to code it in macro?
> > Thanks in advance for any suggestions
> > Eric

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning macro buttons to macro code in another file Enz Microsoft Excel Programming 2 25th May 2009 06:44 PM
Slow code when used as VBA code instead of macro (copying visible columns) jgrappy@gmail.com Microsoft Excel Programming 3 2nd Apr 2007 05:26 PM
Can I use code/macro to change code/macro in an existing file? =?Utf-8?B?U2NvdHQgQmVkb3dz?= Microsoft Excel Programming 2 14th Feb 2007 05:50 AM
do anybody have a sample code for executing excel macro from vb code?<eom> B Deepak Microsoft Excel Programming 2 30th Sep 2005 09:59 AM
Adding macro code to Personal Macro Workbook mika Microsoft Excel Misc 2 16th Oct 2003 09:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 AM.