LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default add-in macro strange errors--method sheets of object workbook fail

Help! I'm a macro newbie and this is driving me nuts!

I've tried everything, but I still get erratic behavior from the macro
below. The macro copies a worksheet from a file and inserts as the first
worksheet in the active workbook. I want to distribute the macro to other
Excel users at work, so I'd like to make it as bullet-proof as I can.

If I open Excel and immediately run the macro I get this error on the third
line from the bottom of macro:

Run-time error '-2147221080(800401a8)' method 'sheets' of object '_workbook'
failed.

If I open a previously saved file then run the macro it works fine. It
seemed to run fine when I tested it before saving it as an .xla file.

Any suggestions? There must be some way to avoid this error, or at least
trap it. I've been working on this a few days now with no success, and it's
driving me crazy!

Thanks in advance for the help!

================================
Sub AddDocumentation()

Dim wbDOC As Workbook
Dim CurrentWb As Workbook

Set CurrentWb = ActiveWorkbook


Set wbDOC = Workbooks.Open(Filename:="C:\NRGSCExcelUtil\Docume ntation
Template v7 10 27 04.xls")
wbDOC.Sheets("General Documentation").Copy Befo=CurrentWb.Sheets(1)
ActiveSheet.Name = "General Documentation"
wbDOC.Close SaveChanges:=False
End Sub

==========================================

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error message Method €˜Add of object €˜CommandBar Controls fail? Sandy Pringle Excel Discussion (Misc queries) 2 October 30th 09 02:45 PM
Charts.Add error '1004' Method 'Add' of object 'Sheets' failed Corey Charts and Charting in Excel 1 December 28th 06 02:15 PM
OpenText Method of Workbook Object Question John Excel Programming 2 October 20th 04 07:39 PM
Sheets select method fails when workbook is opened by another workbook Mike Excel Programming 2 June 8th 04 04:17 AM
method vbproject of object workbook fail Chrispy[_2_] Excel Programming 4 January 9th 04 06:56 AM


All times are GMT +1. The time now is 09:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"