Array of Workbooks VBA

mardi 24 mars 2015

I have a list of excel file names in a range in my workbook. I want to take that range of file names, convert it into an array, then open each one and perform a few operations inside before saving and closing. What is the best way to do this?



The following is the part of the code I'm having trouble with. When it goes to open the first pastefile, I get an error that the subscript is out of range.






Quote:








Dim PasteFiles As Variant



PathPasteFiles = ThisWorkbook.Sheets("Inputs").Range("b7:b8")

PasteFiles = ThisWorkbook.Sheets("Inputs").Range("e7:e8")



counter = 1



Dim MyWB As Workbook



'Open each file, paste, save, then close

While counter <= UBound(PasteFiles)





Workbooks.Open PathPasteFiles(counter), Notify:=False



PathPasteFiles(counter).Worksheets(TabString).Rang e(RangeString).PasteSpecial Paste:=xlPasteValues

PathPasteFiles(counter).Worksheets(TabString).Rang e(RangeString).PasteSpecial Paste:=xlPasteFormats



PathPasteFiles(counter).Save

PathPasteFiles(counter).Close



counter = counter + 1

Wend








Array of Workbooks VBA

0 commentaires:

Enregistrer un commentaire

 

Lorem

Ipsum

Dolor