I have a simple function contained within an AciveX dll. Basically I want to copy an existing worksheet to the same workbook, and change the name. Here is the function
VB Code:
Public Function AddSheetCopy(CopyName As String, NewName As String) For Each xlSheet In xlApp.worksheets If xlSheet.Name = NewName Then MsgBox ("sheet exists") Exit Function End If Next xlSheet MsgBox (xlApp.worksheets(1).Name) xlApp.worksheets(CopyName).Copy after:=xlApp.worksheets(xlApp.worksheets.Count) xlApp.activesheet.Name = NewName Set xlSheet = xlApp.activesheet End Function
The above function does exactly as I intend it to do, with one problem. Above there is a message box which displays the name of the first sheet, I don't really want to be plagued with this every time I call the function (I placed it there for debugging). If I comment out that line, the function fails. Instead of making a copy of "copyname" it makes a copy of the current active sheet. I have tries just about everything I can think of to make it work, yet it still doesn't.
Any ideas? thanks in advance.




Reply With Quote