ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro Help (https://www.excelbanter.com/excel-programming/392522-macro-help.html)

[email protected]

Macro Help
 
I have created a macro that copies and pastes info from one
spreadsheet to another in the format the I need.

What I am attempting to figure out now is how can I run this macro on
multiple files. There are about 10 files per day that i need to run
this macro on and the file names will change daily. How can i have
the macro reference the desktop folder that i will store these files
in and run the macro through all files? Is this possible?

Secondly, in the macro, the last step is create an XML file out of the
spreadsheet the macro created. It always stops at this step,
prompting me to name the file. Is there a way to automatically name
the file the contents of a specific cell and save it to a destination?

I would really appreciate anyones help with this. I'm clearly not
very skilled with this, so any help you can offer would be greatly
appreciated :)


Dave Miller

Macro Help
 
Just change sDir to the name of the folder you want to import from,
not sure about the XML part though (I'm still on xl2k):

Sub TryThis()
Dim myBook As Workbook, _
ThisSheet As Worksheet, _
sDir, sFile As String

sDir = "C:\FolderName\"
sFile = "*.xls"

Set ThisSheet = ActiveWorkbook.Sheets(1)

With Application
.DisplayAlerts = False
With .FileSearch
.NewSearch
.LookIn = sDir
.Filename = sFile
.MatchTextExactly = True
If .Execute < 0 Then Exit Sub
For i = 1 To .FoundFiles.Count - 1
Set myBook = Workbooks.Open(.FoundFiles(i))
With myBook
.Sheets(1).Range("A1").CurrentRegion.Copy
ThisSheet.Range("A65536").End(xlUp).Offset(1,
0).PasteSpecial
.Close
End With
Next i
End With
.DisplayAlerts = True
End With

Set myBook = Nothing
Set ThisSheet = Nothing
End Sub



All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com