Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time Error 1004

Status
Not open for further replies.

Dan8376

Technical User
Jan 29, 2002
25
US
I'm having a problem running a macro from a command button in Excel. I have this procedure that I want to run from the click of a button. The procedure runs great if I run it from the VB window or the immeadiate window. When I try to run it by clicking on a command button, I get the run time error 1004: Method 'Goto' of object _Application' failed.

Here is a sample of the code:

Sub PrintAlpha()
Dim str As String
Dim i As Integer
i = 0
Do
str = Range("PrintCommissions!F6").Offset(i, 0)
Application.Goto Reference:=str
Selection.PrintOut Copies:=1, Collate:=True
i = i + 1
Loop Until Range("PrintCommissions!F6").Offset(i, 0) = ""
End Sub

The error is happening on the following line:
Application.Goto Reference:=str

This code is trying to print a list of range names that are defined in the excel workbook.

Thanks
Dan

 
This might help.

Code:
Sub PrintAlpha()
Dim c As Range
Set c = Range("PrintCommissions!F6")
Do
    Range(c.Value).PrintOut Copies:=1, Collate:=True
    Set c = c.Offset(1, 0)
Loop Until c.Value = ""
End Sub


Chris

-------------------------------------------------------------
"Don't be deceived. We're all temporary employees.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top