Printing issue

L

Living the Dream

Hi everyone.

Even though the company has upgraded to 2007 recently, up until this
week, this code has been used to great success.

Now it throws up the following error:

Run-time error ‘1004’: Method ‘Range’ of Object’_Worksheet’ Failed.

Any thoughts or suggestions as to why all of a sudden it is halting at
this point:
.........................................................................

If Set_PageSetup(myWkS, myWkS.Range("LHdrText")) Then
myWkS.PrintOut Preview:=True
Else
MsgBox "An error occured doing PageSetup for sheet '" _
& myWkS.Name & "'!"

........................................................................

THE FULL CODE:

Function Set_PageSetup(Target As Worksheet, LHdrText As String) As Boolean
myDate = Format(Date, "Ddd, dd-Mmm-yy")
On Error GoTo ErrExit
With Target.PageSetup
.PrintArea = Selection.Address
.PrintTitleRows = "$1:$1"
.LeftHeader = LHdrText
.RightHeader = myDate
.FitToPagesWide = 1
End With
ErrExit:
Set_PageSetup = (Err = 0)
If Not Set_PageSetup Then wks.CenterHeader = "": wks.PrintArea = ""
End Function


Sub PrintHDCReports()
Dim myWkS As Worksheet
Set myWkS = ActiveSheet
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
If Set_PageSetup(myWkS, myWkS.Range("LHdrText")) Then
myWkS.PrintOut Preview:=True
Else
MsgBox "An error occured doing PageSetup for sheet '" _
& myWkS.Name & "'!"
End If
End Sub

Appreciate any thoughts and assistance
TIA
Mick.
 
D

Don Guillett

Hi everyone.



Even though the company has upgraded to 2007 recently, up until this

week, this code has been used to great success.



Now it throws up the following error:



Run-time error �1004�: Method �Range� of Object�_Worksheet� Failed.



Any thoughts or suggestions as to why all of a sudden it is halting at

this point:

........................................................................



If Set_PageSetup(myWkS, myWkS.Range("LHdrText")) Then

myWkS.PrintOut Preview:=True

Else

MsgBox "An error occured doing PageSetup for sheet '" _

& myWkS.Name & "'!"



.......................................................................



THE FULL CODE:



Function Set_PageSetup(Target As Worksheet, LHdrText As String) As Boolean

myDate = Format(Date, "Ddd, dd-Mmm-yy")

On Error GoTo ErrExit

With Target.PageSetup

.PrintArea = Selection.Address

.PrintTitleRows = "$1:$1"

.LeftHeader = LHdrText

.RightHeader = myDate

.FitToPagesWide = 1

End With

ErrExit:

Set_PageSetup = (Err = 0)

If Not Set_PageSetup Then wks.CenterHeader = "": wks.PrintArea = ""

End Function





Sub PrintHDCReports()

Dim myWkS As Worksheet

Set myWkS = ActiveSheet

Range("A1").Select

Range(Selection, Selection.End(xlToRight)).Select

Range(Selection, Selection.End(xlDown)).Select

If Set_PageSetup(myWkS, myWkS.Range("LHdrText")) Then

myWkS.PrintOut Preview:=True

Else

MsgBox "An error occured doing PageSetup for sheet '" _

& myWkS.Name & "'!"

End If

End Sub



Appreciate any thoughts and assistance

TIA

Mick.

Don't see how this workedd
myWkS.PrintOut Preview:=True
maybe
myWkS.preview:=True

what are you trying to do. If desired, send file to dguillett @gmail.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top