我正在尝试使用宏来在特定工作表之后添加工作表。让我们说这张表名为102014.我希望这个宏在102014之后创建一个名为112014的表,但我不能使用select或活动表,因为它实际上是一个大宏的一部分,我来回切换工作簿之间。这是我试图做的,没有成功:
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
宏只是传递最后一行并转到另一行,没有错误,没有任何错误。如您所见,我有一个包含工作表名称和文件名的列表,这是我从中获取thismonth
,lastmonth
和wbname
变量的位置。
我做错了什么?
答案 0 :(得分:1)
使用.Add(After:= ...
请注意所需的冒号。