Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
I'm coming across strange macro behavior in the macro below. The macro is supposed to copy a worksheet named "General Documentation" from a file and add it as the first worksheet in the current file. During my testing, everything worked fine. But when I created an add-in sheet containing the macro below and others, I get strange behavior. When I open a new worksheet and immediately run the macro, I get a "method 'sheets' of object _workbook failed" error. This error only seems to occur when I open Excel, which starts with the default "Book1", then immediately run the macro. It doesn't pop up if I enter data in "Book1" before I run it or if I run it on a previously-saved workbook. This is the line that errors: Workbooks(wbDOCname).Sheets("General Documentation").Copy Befo=CurrentWb.Sheets(1) Any thoughts on what's happening here? Thanks! ============================================== Sub AddDocumentation() Dim wbDOC As Workbook Dim wbDOCpath As String Dim wbDOCname As String Dim CurrentWb As Workbook Set CurrentWb = Nothing Set CurrentWb = ActiveWorkbook wbDOCpath = "C:\NRGSCExcelUtil\" wbDOCname = "Documentation Template v7 10 27 04.xls" If CurrentWb Is Nothing Then MsgBox "No workbook to add General Documentation to!", vbinformaiton Exit Sub End If If SheetExists("General Documentation") Then MsgBox "General Documentation sheet already exists in this workbook", vbInformation Exit Sub End If If WorkbookIsOpen(wbDOCname) Then Set wbDOC = Workbooks(wbDOCname) Else If FileExists(wbDOCpath & wbDOCname) Then Set wbDOC = Workbooks.Open(Filename:=wbDOCpath & wbDOCname) Else MsgBox "The Documentation Template file was not found", vbInformation Exit Sub End If End If 'MsgBox "Adding sheet to " & CurrentWb, vbInformation Workbooks(wbDOCname).Sheets("General Documentation").Copy Befo=CurrentWb.Sheets(1) ActiveSheet.Name = "General Documentation" Workbooks(wbDOCname).Close SaveChanges:=False End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Strange Copy/Paste behavior | Excel Discussion (Misc queries) | |||
Strange copy & paste behavior | Excel Discussion (Misc queries) | |||
worksheet copy problem | Excel Programming | |||
worksheet copy problem | Excel Programming |