2015-09-10 37 views
0

我想要使用宏来添加表后特定工作表。假设这张表名为102014.我希望这个宏在名为112014的102014之后创建一张表,但是我不能使用select或active表,因为它实际上是一个大宏的一部分,我来回切换在工作簿之间。这里是我试图做的,没有成功:'工作簿.sheets.add后'不工作

dim wbname as string 
dim thismonth as string 
dim lastmonth as string 

thismonth = ThisWorkbook.Worksheets("Sheet2").Cells([address of a cell with the name of the sheet).Value 
lastmonth = ThisWorkbook.Worksheets("Sheet2").Cells([address of a cell with the name of the sheet).Value 

wbname = ThisWorkbook.Sheets("Sheet2").Cells([address of a cell with the file name here]) 
Workbooks(wbname).Sheets.Add(After = wbkname.Sheets(lastmonth)).Name = thismonth 

宏只是将最后一行,并进入到另外一个,没有错误,什么都没有。正如你所看到的,我有一个带有表名和文件名的列表,这是我从中获得thismonthlastmonthwbname变量的地方。

我在做什么错?

+1

look [here](http://stackoverflow.com/questions/20697706/how-to-add-a-named-sheet-at-the-end-of-all-excel-sheets) –

+0

你需要一个“后”冒号后 – 9Deuce

回答

1

使用.Add(After:= ...

请注意所需的冒号。

+0

非常感谢你的队友,完美的工作! –

相关问题