I needed a macro that would arrange all the pages of a document in another document in the form of a grid. So I started to program this macro. After finishing I noticed that after performing the task once it threw a warning. But my surprise was bigger when I saw that if I debugged and pressed f5 it continued perfectly until the next cycle.
the code:
Sub documentTeTeEse() Dim DocO As Document Set DocO = ActiveDocument ancho = DocO.ActivePage.SizeWidth alto = DocO.ActivePage.SizeHeight iter = DocO.Pages.Count If iter < 10 Then maxx = iter * ancho Else maxx = ancho * 10 End If maxy = RoundUp(iter / 10) * alto Dim DocN As Document Set Propi = CreateStructCreateOptions With Propi .Name = DocO.Name + " - Grid" .PageWidth = maxx .PageHeight = maxy .Resolution = 300 .Units = DocO.Unit End With Set DocN = Application.CreateDocumentEx(Propi) DocN.ReferencePoint = cdrTopLeft DocN.DrawingOriginX = -DocN.ActivePage.SizeWidth / 2 DocN.DrawingOriginY = DocN.ActivePage.SizeHeight / 2 For Each p In DocO.Pages nombre = p.Name x = (((p.Index - 1) Mod 10) * ancho) y = -RoundDown((p.Index - 1) / 10) * alto p.Layers(2).Shapes.All.Copy DocN.Pages(1).Layers(2).Paste ActiveSelection.Group.Name = nombre ActiveSelection.PositionX = x ActiveSelection.PositionY = y Next pEnd Sub
how could I disable the warning -2147467259 (80004005) or prevent it from coming up.
In general, the best solution is to find out why your code is generating an error.
If you want the macro to continue after encountering an error, you could include this in your code:
On Error Resume Next
You could put that fairly early in your sub, e.g., after your declarations, but before you really start doing anything.
That is something to use with a great deal of caution, because ignoring errors can produce unexpected results.
That's what I was looking for, thank you.although now with that code it doesn't work as before, I think the problem is that the for is solving things asynchronously, and that's why every cicle the program stops. I'll see if I can force the synchrony.