Your technology certification is waiting. Enroll in Cloud Class ®
Public Sub AddPageAndImportImageExample()
Dim pg As Visio.Page
Set pg = Visio.ActiveDocument.Pages.Add()
pg.Name = "Example" & pg.Document.Pages.Count '//...note: must be unique for the document!
'// Import an image to the page, and get it
'// as a shape object:
Dim shp As Visio.Shape
Set shp = pg.Shapes(pg.Shapes.Count) '//...ie: the top-most shape, which was just added
'// Make the shape fit the page. We'll need to calculate
'// how much bigger or smaller the image is, relative
'// to the page:
Dim pw As Double, ph As Double
pw = pg.PageSheet.CellsU("PageWidth").ResultIU
ph = pg.PageSheet.CellsU("PageHeight").ResultIU
Dim w As Double, h As Double
w = shp.CellsU("Width").ResultIU
h = shp.CellsU("Height").ResultIU
Dim f As Double, fw As Double, fh As Double
fw = w / pw
fh = h / ph
If (fw > fh) Then
f = 1 / fw
f = 1 / fh
'// Change the size of the image by f:
shp.CellsU("Width").ResultIU = shp.CellsU("Width").ResultIU * f
shp.CellsU("Height").ResultIU = shp.CellsU("Height").ResultIU * f
'// Center the image-shape on the page
shp.Cells("PinX").FormulaForceU = "ThePage!PageWidth*0.5"
shp.Cells("PinY").FormulaForceU = "ThePage!PageHeight*0.5"
Set pg = Nothing
Set shp = Nothing
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
This course teaches how to install and configure Windows Server 2012 R2. It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).