Hi everyone. I'm building a macro that performs a lot of functions, but for one area in particular I need your help. Mostly I don't know the right syntax for this step.
The first workbook (call it "File1.xls") has only one worksheet called "Inputs". Based on a few user settings, it opens a target workbook ("File2.xls") with an unknown number of worksheets and unknown worksheet names.
I want to add these worksheets to File1.xls in the same order with the same names, copy the formatting (but not the data) to each newly created worksheet, and finally read in the number of rows and columns that are actually used in each worksheet.
I can add the correct number of worksheets using the code below, and I can read the worksheet names. Unfortunately the new worksheets get added to the left of the inputs tab, while I want them to be added to the right. Also, I can't figure out how to apply the names to the newly created worksheets. Finally, I don't know how to copy the formats over or read the number of used rows and columns in each worksheet.
Thanks!
The first workbook (call it "File1.xls") has only one worksheet called "Inputs". Based on a few user settings, it opens a target workbook ("File2.xls") with an unknown number of worksheets and unknown worksheet names.
I want to add these worksheets to File1.xls in the same order with the same names, copy the formatting (but not the data) to each newly created worksheet, and finally read in the number of rows and columns that are actually used in each worksheet.
I can add the correct number of worksheets using the code below, and I can read the worksheet names. Unfortunately the new worksheets get added to the left of the inputs tab, while I want them to be added to the right. Also, I can't figure out how to apply the names to the newly created worksheets. Finally, I don't know how to copy the formats over or read the number of used rows and columns in each worksheet.
Code:
Workbooks.Open FileName:="C:\Path\File2.xls", ReadOnly:=True
Windows("File1.xls").Activate
For Each Sheet In Workbooks("File1.xls").Worksheets
Worksheets.Add
WorkSheetName = Sheet.Name
Next Sheet
Thanks!