Macro runs different when stepping through code

SY24

New Member
Joined
Oct 6, 2023
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Greetings,

recently I programmed a macro thats supposed to print labels via our Dymo LabelWriter 450. It needs a special pagesize setup in VBA in order to work:
VBA Code:
    With ActiveSheet.PageSetup
        .PaperSize = 220
    End With
Where 220 is the index of the pagesize for this printer. I verified that by recording a macro and setting the pagesize manually.
ExcelIssue01.png


Running the macro on my machine works just fine. The pagesize is applied correctly and the text appears perfectly centered on the printed labels, as intended.
ExcelIssue02.png


The actual problem occurs when running this macro on my colleague's machine (they have an identical Dymo printer connected). The text is shifted to almost outside the border of the label.
ExcelIssue03.png


This does not happen however if I manually step through the macro (F8) on my colleague's machine. Then it prints the label just fine.

So I am somewhat confused at this point. I feel like the "PaperSize" parameter is skipped when running the macro normally. If there is anything I can try or should check, please let me know! Any help is greatly appreciated.

SY24
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try to include DoEvents after altering the PageSetup
and maybe: Application.PrintCommunication = True
 
Upvote 1
Solution
Try to include DoEvents after altering the PageSetup
and maybe: Application.PrintCommunication = True
Hey bobsan,

thanks for the reply!
Setting Application.PrintCommunication = True right before the PageSetup code did the magic.
I didn't notice DoEvents to affect anything. What is it used for usually?

Greetings
 
Upvote 0
I didn't notice DoEvents to affect anything. What is it used for usually?
It's a sort of cure for slower processes, which cannot catch-up with the rushing code. You basically tell the code to wait a moment so some bits of it get some more time to finish what they are doing e.g. updating statusbar or progress indicators.
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,601
Members
452,658
Latest member
GStorm

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