• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Print button in worksheet

ncexcel

New Member
Hi, i am working on a planning tool for work and I want to make a print button...
I have already made the button but when I press it, it says this: "Run-time error '1004': Method 'PrintOut' of object 'Range' failed"
I coded the button this:
Sub Udskriv()
Range("A1:T21").PrintOut
End Sub

A helping hand would be much appreciated :)
 
Hi ! As PrintOut method does very not exist within Range alone so the reason of your error message !​
Like you can easily check on VBE side just moving the text cursor on PrintOut statement then hit the F1 key to open the VBA help​
so easy to see this method belongs to a sheet object ...​
The best way to learn how it must work : activate the Macro Recorder, setup the range to print within the sheet print options,​
launch the print then stop the Macro Recorder in order to see what is its generated VBA code ...​
 
>>> use code - tags <<<
Code:
Sub Udskriv()
    With ActiveSheet
        .PageSetup.Orientation = xlPortrait ' or xlLandscape if preferred
        .PageSetup.Zoom = False
        .PageSetup.FitToPagesWide = 1
        .PageSetup.FitToPagesTall = False
        .Range("A1:T21").PrintOut Preview:=True
    End With
End Sub
 
Last edited by a moderator:
>>> use code - tags <<<
Code:
Sub Udskriv()
    With ActiveSheet
        .PageSetup.Orientation = xlPortrait ' or xlLandscape if preferred
        .PageSetup.Zoom = False
        .PageSetup.FitToPagesWide = 1
        .PageSetup.FitToPagesTall = False
        .Range("A1:T21").PrintOut Preview:=True
    End With
End Sub
Thank you! That worked for me :)
 
Back
Top