LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Open file, copy field and paste into an Excel doc! - Pl help ..


Hi there,

Thank you very much for you help :) I had to tweak it slightly. But
otherwise it was great :) Thanks for your help again.

I am posting the code below which I hope might be of use to somebody
some day. Here I go -

.................................................
Private Sub CommandButton1_Click()

Dim i As Integer
Dim wb As Workbook
Dim outrng As Range

i = 1
Set fs = Application.FileSearch
Set wb = ThisWorkbook


With fs
..LookIn = "X:/"
..Filename = "*.*"
..SearchSubFolders = False
..Execute
For i = 1 To .FoundFiles.Count
Range("A" & i).Value = .FoundFiles(i)

'THIS IS TO COPY THE AMOUNT
Workbooks.Open .FoundFiles(i)
Worksheets(1).Range("B3").Copy
Workbooks(FileNameOnly(.FoundFiles(i))).Close
savechanges = False
With wb.Worksheets("Sheet1")
..Range("B" & i).PasteSpecial
Operation:=xlPasteSpecialOperationAdd
End With

Next
End With

End Sub


Function FileNameOnly(pname) As String
' Returns the filename from a path/filename string
Dim i As Integer, length As Integer, temp As String
length = Len(pname)
temp = ""
For i = length To 1 Step -1
If Mid(pname, i, 1) = Application.PathSeparator Then
FileNameOnly = temp
Exit Function
End If
temp = Mid(pname, i, 1) & temp
Next i
FileNameOnly = pname
End Function
.................................................

Harish Mohanbabu


--
Harish Mohanbab


------------------------------------------------------------------------
Harish Mohanbab's Profile: http://www.excelforum.com/member.php...fo&userid=6332
View this thread: http://www.excelforum.com/showthread...hreadid=392859

 
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
Excel Copy, Paste not working properly, corrupts file Marvin B Excel Discussion (Misc queries) 1 March 3rd 09 04:21 PM
Copy and paste special - values into new excel file [email protected] Excel Discussion (Misc queries) 1 October 12th 05 11:02 PM
Open file, Copy a column and paste this into a new Excel doc - Pl Harish Mohanbabu[_2_] Excel Programming 1 August 4th 05 01:58 PM
From excel - open word doc and copy form field contents to excel c gnome88 Excel Programming 0 July 25th 05 11:45 PM
Macro to Copy data from e-mail and paste it into a field on a website joebobcletusjr Excel Programming 0 February 16th 05 05:19 PM


All times are GMT +1. The time now is 03:37 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"