I want my selection to reduce 4 mm from page size. for example my page size is 100*100mm and my design is 99*99mm or 150*150mm. I want my selection to reduce 4mm and after reducing it automatically become 96*96mm and then group everything on the current page and also place center on the page.
Charlie,
Thank you for posting some code, as Mek says it looks like you grabbed it from another post and it doesn't do what you want. So Lets start from the beginning and work through this together so we may all learn. I am going to keep this very simple, we can improve it along the way.
You want to work with two items, the page and the selection. So it is a good idea to define a variable for the page and your selection which will be a ShapeRange, you so that like this:
Dim p As Page Dim sr As ShapeRange
Now we need to set the newly define variable to a page and the selection. You can do that like this:
Set p = ActivePage Set sr = ActiveSelectionRange
Now that the editor knows that sr is a ShapeRange if you type sr. you will get a list of things you can do to the ShapeRange or get from the ShapeRange. You want to change its size, so look through the list and see what might work for you.
You should see and option for SetSize. And you want to set the size of the selection to the page. So you would do this:
sr.SetSize p.SizeWidth, p.SizeHeight
By doing this the selection should now be sized to the same size as your page. But wait, you wanted the selection to be 4mm smaller than the page size, so here comes your homework. Using the same line above how would you modify it so that instead of being exactly the page size that it would be 4mm smaller?
To help, I will explain a little more about the SetSize, it is setting the Width and the Height. So you could type in numbers like this:
sr.SetSize 100, 100
That would make your selection 100 mm x 100 mm assuming you are working in millimeters. If you do the following:
sr.SetSize 96 , 96
It would make the selection 96 mm x 96 mm.
The p.SizeWidth gets the size of the page, and the p.SizeHeight gets the height of the page, this is why the selection would then change to the size of the page.
Here is the sample code all put together for you:
Sub SizeToPageWithMargin() Dim p As Page Dim sr As ShapeRange Set p = ActivePage Set sr = ActiveSelectionRange sr.SetSize p.SizeWidth, p.SizeHeight End Sub
Happy Coding,
-Shelby
Sub SizeToPageWithMargin() Dim p As Page Dim sr As ShapeRange ActiveDocument.Unit = cdrMillimeter ActiveDocument.ReferencePoint = cdrCenter Set p = ActivePage Set sr = ActiveSelectionRange reduce = 4 sr.SetSize p.SizeWidth - reduce, p.SizeHeight - reduce sr.Group sr.AlignRangeToPageCenter cdrAlignVCenterEnd Sub