Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default update excel files using a vba script


Hello. Is there a way i could update one or several files at once, using
data from another excel file? For exemple in file exemple1.xls i have in
cells a2 and a3 certain values that i want in files exemple2.xls and
exemple3.xls. I would need this for 2 or more files Thank you!


--
adinic
------------------------------------------------------------------------
adinic's Profile: http://www.excelforum.com/member.php...o&userid=31529
View this thread: http://www.excelforum.com/showthread...hreadid=533385

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default update excel files using a vba script

In the files you want to share the data, you could open them and put in a
formula

in one cell
='C:\Myfolder\[exemple1.xls]Sheet1'!A2

and in another cell another formula

='C:\Myfolder\[exemple1.xls]Sheet1'!A3

Do this in each of the workbooks.

If you don't want a formula, then you would have to both the source workbook
and the destination workbook open at the same time (which you can do in code)

so in the source workbook you would have code like

Sub UpdateValues()

Dim rng1 as Range, bk as Workbook
Dim i as Long
set rng1 = Thisworkbook.Worksheets(1).Range("A2")
for i = 2 to 5
set bk = workbooks.open("C:\myfolder\exemple" & i & ".xls")
bk.worksheets(1).Range("A2") = rng1.Value
bk.Worksheets(1).Range("A3") = rng1.offset(1,0).Value
bk.Close SaveChanges:=True
Next

End Sub

--
Regards,
Tom Ogilvy

"adinic" wrote:


Hello. Is there a way i could update one or several files at once, using
data from another excel file? For exemple in file exemple1.xls i have in
cells a2 and a3 certain values that i want in files exemple2.xls and
exemple3.xls. I would need this for 2 or more files Thank you!


--
adinic
------------------------------------------------------------------------
adinic's Profile: http://www.excelforum.com/member.php...o&userid=31529
View this thread: http://www.excelforum.com/showthread...hreadid=533385


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default update excel files using a vba script


Thank you very much for your help. But i would need an "open" window so
that i can select the files that i want to update. I would also need
this window to open at a specified location. Thank you again!


--
adinic
------------------------------------------------------------------------
adinic's Profile: http://www.excelforum.com/member.php...o&userid=31529
View this thread: http://www.excelforum.com/showthread...hreadid=533385

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default update excel files using a vba script

use
application.GetOpenFileName

with the multiselect property set to true.

then loop through the returned array with the code I provided.

You can use Chdrive and Chdir to specify the location where GetOpenFileName
would open.


--
Regards,
Tom Ogilvy


"adinic" wrote:


Thank you very much for your help. But i would need an "open" window so
that i can select the files that i want to update. I would also need
this window to open at a specified location. Thank you again!


--
adinic
------------------------------------------------------------------------
adinic's Profile: http://www.excelforum.com/member.php...o&userid=31529
View this thread: http://www.excelforum.com/showthread...hreadid=533385


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default update excel files using a vba script


Unfortunately i have no idea how to do that. I would apreciate very much
if you could post the entire code. Thank you so much!


--
adinic
------------------------------------------------------------------------
adinic's Profile: http://www.excelforum.com/member.php...o&userid=31529
View this thread: http://www.excelforum.com/showthread...hreadid=533385



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default update excel files using a vba script

Sub UpdateFiles()
Dim v As Variant
Dim rng1 As Range, bk As Workbook
Dim i As Long
ChDrive "C"
ChDir "C:\MyFolder"

v = Application.GetOpenFilename( _
FileFilter:="Excel Files (*.xls),*.xls", _
Title:="Select Multiple Files", _
MultiSelect:=True)
If IsArray(v) Then
Set rng1 = ThisWorkbook.Worksheets(1).Range("A2")
For i = LBound(v) To UBound(v)
Set bk = Workbooks.Open(v(i))
bk.Worksheets(1).Range("A2") = rng1.Value
bk.Worksheets(1).Range("A3") = rng1.Offset(1, 0).Value
bk.Close SaveChanges:=True
Next
Else
MsgBox "No files to process"
End If

End Sub

--
Regards,
Tom Ogilvy


"adinic" wrote:


Unfortunately i have no idea how to do that. I would apreciate very much
if you could post the entire code. Thank you so much!


--
adinic
------------------------------------------------------------------------
adinic's Profile: http://www.excelforum.com/member.php...o&userid=31529
View this thread: http://www.excelforum.com/showthread...hreadid=533385


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Excel Database via Access Main Database with a script Finnbar New Users to Excel 2 November 3rd 08 07:24 PM
Script for Multiple Files Neil Excel Discussion (Misc queries) 5 April 10th 08 10:13 PM
Stand alone VBA script files tishoo Excel Discussion (Misc queries) 6 December 29th 06 06:02 PM
Update a workbook from a script [email protected] Excel Discussion (Misc queries) 1 March 8th 06 02:30 PM
Script or Tool to Update Excel Links Just_Buy Excel Programming 1 April 13th 04 11:08 PM


All times are GMT +1. The time now is 09:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"