V
Vet Tech
I'm a relative newbie at VB but I've managed to cobble together bits
of code gleaned from this NG which enables me to extract selected
data from a group of closed workbooks located in a particular folder
( located at "C:\Temp\Survey) and then save it to another workbook
called Update.xls, in worksheet called Get Data. This is based on two
macros - the most significant of which is based on a development
originally done by Nikos Yannacopoulos.
I want to write an extra couple of lines that will get the name of
each closed workbook in the folder. Here is the code for both macros.
the latter one has been shortened so that it shows the principle
involved. Here is the code:-
Private Sub Process_All_WorkBooks_Click()
' Process_All_Workbooks Macro
' This Macro will open all spreadsheets in a particular folder.
' It will then run another Macro
' Macro created by Nikos Yannacopoulos.
Dim fs, f, f1
Dim strFile As String
fldr = "C:\Temp\Survey\" 'Put your folder path here.
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(fldr)
Set f1 = f.Files
i = 0
Application.ScreenUpdating = False
For Each f2 In f1
strFile = fldr & f2.Name
If Right(strFile, 4) = ".xls" Then
Workbooks.Open strFile
Call Get_Data(f2.Name) 'Call another macro or write code to do
what youwant here.
Windows(f2.Name).Activate
ActiveWorkbook.Close savechanges:=False 'Change accordingly.
True will save the spreadsheet and False will not.
End If
Next
Application.ScreenUpdating = True
End Sub
Private Sub Get_Data(ExcelFileName As String)
Workbooks(ExcelFileName).Worksheets("Working").Range("L2:L2").Copy
Workbooks("Update.xls").Worksheets("Get Data").Range("E65536").End
(xlUp).Offset(1).PasteSpecial
End Sub
Any help would be much appreciated.
VT
of code gleaned from this NG which enables me to extract selected
data from a group of closed workbooks located in a particular folder
( located at "C:\Temp\Survey) and then save it to another workbook
called Update.xls, in worksheet called Get Data. This is based on two
macros - the most significant of which is based on a development
originally done by Nikos Yannacopoulos.
I want to write an extra couple of lines that will get the name of
each closed workbook in the folder. Here is the code for both macros.
the latter one has been shortened so that it shows the principle
involved. Here is the code:-
Private Sub Process_All_WorkBooks_Click()
' Process_All_Workbooks Macro
' This Macro will open all spreadsheets in a particular folder.
' It will then run another Macro
' Macro created by Nikos Yannacopoulos.
Dim fs, f, f1
Dim strFile As String
fldr = "C:\Temp\Survey\" 'Put your folder path here.
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(fldr)
Set f1 = f.Files
i = 0
Application.ScreenUpdating = False
For Each f2 In f1
strFile = fldr & f2.Name
If Right(strFile, 4) = ".xls" Then
Workbooks.Open strFile
Call Get_Data(f2.Name) 'Call another macro or write code to do
what youwant here.
Windows(f2.Name).Activate
ActiveWorkbook.Close savechanges:=False 'Change accordingly.
True will save the spreadsheet and False will not.
End If
Next
Application.ScreenUpdating = True
End Sub
Private Sub Get_Data(ExcelFileName As String)
Workbooks(ExcelFileName).Worksheets("Working").Range("L2:L2").Copy
Workbooks("Update.xls").Worksheets("Get Data").Range("E65536").End
(xlUp).Offset(1).PasteSpecial
End Sub
Any help would be much appreciated.
VT