View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Macro Related to Paste Values

"Akash" wrote:
I have below mentioned formula:
Sub Macro1()

[....]
The only issue is it runs on the single file.
I have aprox 100 similar Files. I want a macro which ask me
to select multiple files and then run a macro to save time.


Your macro seems to have a lot of extraneous operations, as is common for
recorded macros. But assuming it makes sense to do, try the following.

Sub doit()
Dim i As Long
' see GetOpenFilename.FileFilter in help page
fileNames = Application.GetOpenFilename(MultiSelect:=True, _
Title:="click to select one; then press ctrl+A or ctrl+Click")
If TypeName(fileNames) = "Boolean" Then Exit Sub ' cancelled
On Error Resume Next
For i = 1 To UBound(fileNames, 1)
' alternatively, rely on GetOpenFilename.FileFilter
If Right(fileNames(i), 4) = ".xls" Then
Workbooks.Open Filename:=fileNames(i)
If Err = 0 Then
Macro1
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=True
Application.DisplayAlerts = True
End If
End If
Next
End Sub