Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Exporting & Importing with macros

It's possible to write a macro that copy a value that is locate always
in the same position but in different files, this files follow a
nomeclature with logic. And after that paste it in other file.

Example:
In "file1.xls" I want to copy the value in cell "B6" and copy in the
file "all.xls" in cell "B1"
In "file2.xls" I want to copy the value in cell "B6" and copy in the
file "all.xls" in cell "B2"
In "file3.xls"...
And then towards...
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Exporting & Importing with macros

Hi there

One way to do it would be to use the file system object. This method
is handy if you don't want to hard code all the file names you want to
check. It works by checking all the files in the given folder (C:
\Test) in this example. It will loop through all the files and check
for the excel file extension when it files the files it will open them
read the value in B6 and then close the file and write the stored
value into the next available cell in column B of the workbook that
holds the code.

Sub GetCellB6FromEachFile()

Dim intRow As Integer
Dim objFSO As Object
Dim objFile As Object
Dim objFolder As Object
Dim vntB6Value As Variant
Dim wkbk As Workbook

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.getfolder("C:\Test")
intRow = 1

For Each objFile In objFolder.Files
If Right(objFile.Name, 4) = ".xls" Then
Set wkbk = Workbooks.Open(objFile)
With wkbk
vntB6Value = Sheets(1).[B6].Value
wkbk.Saved = True
.Close
Set wkbk = Nothing
End With
ThisWorkbook.Sheets(1).Cells(intRow, 2).Value = _
vntB6Value
intRow = intRow + 1
End If
Next

Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing

End Sub

I hope this helps

Steve
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Exporting & Importing with macros

Option Explicit

Sub getdata()

Dim fn As String
Dim wb As Workbook
Dim index As Long

Const filepath As String = "H:\excel\test\"

fn = Dir(filepath & "*.xls")

Do Until fn = ""
index = Mid(fn, 5, Len(fn) - 8)

Set wb = Workbooks.Open(filepath & fn)
ThisWorkbook.ActiveSheet.Cells(index, "B") =
wb.ActiveSheet.Range("B6").Value
wb.Close False
fn = Dir()
Loop


End Sub


"CAUÃ" wrote:

It's possible to write a macro that copy a value that is locate always
in the same position but in different files, this files follow a
nomeclature with logic. And after that paste it in other file.

Example:
In "file1.xls" I want to copy the value in cell "B6" and copy in the
file "all.xls" in cell "B1"
In "file2.xls" I want to copy the value in cell "B6" and copy in the
file "all.xls" in cell "B2"
In "file3.xls"...
And then towards...
Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Exporting & Importing with macros

my files were BOOK1.xls, BOOK2.xls and so on
so the index started at the 5th character and the number of characters was
the len() of the file name less 8 characters (BOOK + .XLS)

yours will be the same if th efiles all start with the word 'file'


"Patrick Molloy" wrote:

Option Explicit

Sub getdata()

Dim fn As String
Dim wb As Workbook
Dim index As Long

Const filepath As String = "H:\excel\test\"

fn = Dir(filepath & "*.xls")

Do Until fn = ""
index = Mid(fn, 5, Len(fn) - 8)

Set wb = Workbooks.Open(filepath & fn)
ThisWorkbook.ActiveSheet.Cells(index, "B") =
wb.ActiveSheet.Range("B6").Value
wb.Close False
fn = Dir()
Loop


End Sub


"CAUÃ" wrote:

It's possible to write a macro that copy a value that is locate always
in the same position but in different files, this files follow a
nomeclature with logic. And after that paste it in other file.

Example:
In "file1.xls" I want to copy the value in cell "B6" and copy in the
file "all.xls" in cell "B1"
In "file2.xls" I want to copy the value in cell "B6" and copy in the
file "all.xls" in cell "B2"
In "file3.xls"...
And then towards...
Thanks

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
Importing and Exporting Data Adrian G Excel Discussion (Misc queries) 0 July 21st 06 05:45 PM
Exporting/Importing Data baconroll Excel Discussion (Misc queries) 1 April 7th 06 11:27 AM
Importing and Exporting Data to Web Chad Excel Discussion (Misc queries) 1 February 19th 05 06:05 AM
Data Importing and Exporting UNOTech Excel Programming 1 October 19th 04 09:50 AM
Exporting & Importing Macros JRM Excel Programming 4 August 20th 04 03:38 PM


All times are GMT +1. The time now is 02:26 AM.

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

About Us

"It's about Microsoft Excel"