Excel VBA error 400 while link to another sheet

Jagat Pavasia

Active Member
Joined
Mar 9, 2015
Messages
406
Office Version
  1. 2021
Platform
  1. Windows
Dear sir,
I have 2 Sheet in my excel workbook.
First sheet name is "Account" and another name is "Print".
I have put Below VBA in sheet named "Print"
VBA Code:
Sub Print_Jangad()
'
' Print_Jangad Macro
'

'
    Set mynetwork = CreateObject("WScript.network")
    mynetwork.SetDefaultPrinter "Brother QL-800"
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    Application.PrintCommunication = True
    ActiveSheet.PageSetup.PrintArea = ""
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0.196850393700787)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = 300
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = 329
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .EvenPage.LeftHeader.Text = ""
        .EvenPage.CenterHeader.Text = ""
        .EvenPage.RightHeader.Text = ""
        .EvenPage.LeftFooter.Text = ""
        .EvenPage.CenterFooter.Text = ""
        .EvenPage.RightFooter.Text = ""
        .FirstPage.LeftHeader.Text = ""
        .FirstPage.CenterHeader.Text = ""
        .FirstPage.RightHeader.Text = ""
        .FirstPage.LeftFooter.Text = ""
        .FirstPage.CenterFooter.Text = ""
        .FirstPage.RightFooter.Text = ""
    End With
    Application.PrintCommunication = True
    Range("A35:F44").Select
    Selection.PrintOut Copies:=1, Collate:=True
    Set mynetwork = CreateObject("WScript.network")
mynetwork.SetDefaultPrinter "Samsung SCX-3200 Series"
End Sub

And I put link of command button in sheet named "Account" and click on it,
then I got Error 400.

If i put link of command button in sheet named "Print" and click on it then it work as I want.
But I want to put command Button in sheet "Account".


what can i Do ?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
The quickest way would be to add: Sheets("Print").Activate at the beginning of the macro and: Sheets("Account").Activate at the end of it so that the reference is to the right sheet while the macro creates the printed page.
But, even with this addition, I get error #400 on this line: .Papersize = 329. I must say that I cannot use this paper size with my printer. Therefore, if I use a standard paper size the macro does not generate an error any more; so check that parameter too.
 
Upvote 0
The quickest way would be to add: Sheets("Print").Activate at the beginning of the macro and: Sheets("Account").Activate at the end of it so that the reference is to the right sheet while the macro creates the printed page.
But, even with this addition, I get error #400 on this line: .Papersize = 329. I must say that I cannot use this paper size with my printer. Therefore, if I use a standard paper size the macro does not generate an error any more; so check that parameter too.
Did you edit macro and then send me ?
Because i have record vba and create this VBA.
I am a new in VBA .

Please, thank you in advance
 
Upvote 0
This is the first line (beginning) of your macro: Set mynetwork = CreateObject("WScript.network")
and this your last line (end): mynetwork.SetDefaultPrinter "Samsung SCX-3200 Series".
So just Copy/Paste what I said in the first sentence of my post #2.
Then, if you still get Error #400 delete the line I indicated in the second sentence of post #2.
 
Upvote 0

Forum statistics

Threads
1,223,969
Messages
6,175,690
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top