Excel VBA Q: Error 1004 Method method of Object class failed? 
Author Message
 Excel VBA Q: Error 1004 Method method of Object class failed?

  I am trying to run the following VBA macro in Excel:

  Sub cmdPrint_Click()

    Sheets("MySheet").Select
    ActiveSheet.PrintOut

  End Sub

  If I run the macro from the module or from the
  toolbar it works fine.  However if I try to assign
  the macro to a button on a dialogsheet I get runtime
  error: 1004  "Printout method of Worksheet class
  failed" when I click on the button.

  I tried so far adding the line ActiveDialog.Hide
  in case my dialog box was causing a problem, but
  this did not help.

  I have no idea why this won't work and can find it
  in any of my reference manuals.  If anyone knows why
  this fails please email me.

  Thanks
  Joe Feyas



Sun, 19 Jul 1998 03:00:00 GMT  
 Excel VBA Q: Error 1004 Method method of Object class failed?

Feyas ) says:
Quote:

>  I am trying to run the following VBA macro in Excel:

>  Sub cmdPrint_Click()

>    Sheets("MySheet").Select
>    ActiveSheet.PrintOut

>  End Sub

>  If I run the macro from the module or from the
>  toolbar it works fine.  However if I try to assign
>  the macro to a button on a dialogsheet I get runtime
>  error: 1004  "Printout method of Worksheet class
>  failed" when I click on the button.

I think, off the top of my head, its because the activesheet is now the
dialogue sheet and not the one it was when you run from the module. I'd
assume dialogue sheets don't understand the method.

You may want to change the reference to activesheet, perhaps, to a named
sheet, to be sure you refer to the correct sheet.

This is just a guess based on similar problems in the past.



Mon, 20 Jul 1998 03:00:00 GMT  
 Excel VBA Q: Error 1004 Method method of Object class failed?

Quote:


> Feyas ) says:

> >  I am trying to run the following VBA macro in Excel:

> >  Sub cmdPrint_Click()

> >    Sheets("MySheet").Select
> >    ActiveSheet.PrintOut

> >  End Sub

The dialog box has to be dismissed before it can run another sub routine,
which means you have to press the OK or cancel buttons.  You therefore
have to set a switch first by assigning the option button to an option sub
routine where x is the option variable.

sub option_1
  x=1
end   sub

That sets x =1 when you press the option radio button on the dialiog box.
The when you click OK, the dialoig box goes away and the routine
continues.  The routine should continue sonthing like:

   if x=1 then cmdPrint_Click

Good luck



Sat, 25 Jul 1998 03:00:00 GMT  
 Excel VBA Q: Error 1004 Method method of Object class failed?

Quote:

>  I am trying to run the following VBA macro in Excel:
>  Sub cmdPrint_Click()
>    Sheets("MySheet").Select
>    ActiveSheet.PrintOut
>  End Sub

Why not:

Application.WorkBooks("MyBook").Worksheets("MySheet").PrintOut,

in case there is a referencing problem...

-Harri

Quote:
>  Thanks
>  Joe Feyas



Mon, 27 Jul 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. method ~ of object ~ failed 1004

2. PasteSpecial Method of charts causes Run-time error 1004

3. Public Method in a class calling a private method in same class yields ByRef error

4. Run Time error -2147417848 Method Of Object Failed

5. Method Action of object CrystalCtrl failed Error ?

6. ERROR : METHOD OF OBJECT FAILED

7. random error (method execute of object _Connection failed)

8. Error -214722099 Method Connection of Object-current Project Failed

9. Excel AddIn - error 1004

10. Selecting Excel ranges with VB; error 1004

11. followhyperlink method fails to use method constant other than msoMethodGet

12. Class method failed....

 

 
Powered by phpBB® Forum Software