Printout in a loop, keep getting same

MichaelTigers

New Member
Joined
Apr 26, 2017
Messages
1
Hi,I have used below code to fill certain OLEObjects in a loop:Dim rng As RangeDim wsS As WorksheetDim wsD As WorksheetActiveSheet.Copy after:=Sheets(Sheets.Count)Sheets(Sheets.Count).Name = "Sourcebook"Set wsS = Sheets("Sourcebook")Set wsD = Sheets("CMR")Set rng = wsS.Range("A3", Range("A100").End(xlUp))Answer = MsgBox("Je print nu alle CMR's!", vbOKCancel, "Generate CMR") If Answer = vbCancel Then Exit Sub End If wsD.Visible = True For Each rng In wsS.Range("A3", Range("A2").End(xlDown)) wsD.Activate With ActiveSheet .OLEObjects("Shipper").Object.Text = "Ref: " & rng.Offset(0, 9).Value .OLEObjects("Consignee").Object.Text = rng.Offset(0, 0).Value & vbNewLine & _ rng.Offset(0, 11).Value & vbNewLine & _ rng.Offset(0, 12).Value & " " & rng.Offset(0, 13).Value & vbNewLine & _ rng.Offset(0, 14).Value .OLEObjects("Delivery").Object.Text = rng.Offset(0, 12).Value & " " & rng.Offset(0, 13).Value & ", " & rng.Offset(0, 14).Value .OLEObjects("Reference").Object.Text = "" & vbNewLine & _ "" & vbNewLine & _ "" & vbNewLine & _ "" & vbNewLine & _ "ref:" & vbNewLine & _ rng.Offset(0, 9).Value .OLEObjects("Unit").Object.Text = rng.Offset(0, 7).Value .OLEObjects("Description").Object.Text = "Iron ware" & vbNewLine & rng.Offset(0, 6).Value .OLEObjects("Weight").Object.Text = rng.Offset(0, 8).Value .OLEObjects("Code").Object.Text = " Pallet code: " & rng.Offset(0, 15).Value .OLEObjects("Place").Object.Text = rng.Offset(0, 13).Value End With wsD.PrintOut From:=1, To:=1, Copies:=4, preview:=True, ActivePrinter:="\\RTM5\Xerox WorkCentre 7845 CMR" Next rngNow the problem is that I keep getting the same document several times when I run this. While if I go through step by step (F8) it works.Does anyone has the solution for this?Kind regards,
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,214,814
Messages
6,121,711
Members
449,049
Latest member
THMarana

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