Problem to use VBA adding a worksheet in Excel2010

Boban

New Member
Joined
Aug 2, 2011
Messages
1
Hi,

When I changed from Excel2003 to Excel2010 some of my Macros stopped to work. I need a macro that autmatically add a number of worksheet in the end of the workbook, but somethings seems to be wrong in the "Sheet.Add ...." command line, and I do not find the problem, can anyone help me to solve this problem?

Thanks in advance!

Code:

Private Sub CommandButton1_Click()
Dim wb As Workbook
Dim x As Integer
Dim myPath As String
Dim SheetCoreName As String
Dim numtimes As Integer

myPath = ActiveWorkbook.Path

Worksheets("TVS-ber").Copy
Set wb = ActiveWorkbook
wb.SaveAs (myPath & "\TVS-ber.xltm"), FileFormat:=53
' 52 = xlOpenXMLWorkbookMacroEnabled = xlsm (with macro's in 2007-2010)
wb.Close

x = Worksheets("Geometri").Range("A3")

For numtimes = 1 To x
Sheets.Add after:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count), Type:=(myPath & "\TVS-ber.xltm")

ActiveSheet.Range("R2") = numtimes + 6


SheetCoreName = "x = "
ActiveSheet.Name = SheetCoreName & ActiveSheet.Range("S13")

Next

End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top