Solved

Visio 2013

Posted on 2013-11-07
2
680 Views
Last Modified: 2013-11-08
Looking for a vba macro for visio that will import (several) jpg files to use as tracing backgrounds.

Ideally, it would page through a directory insert a jpg and save it to a visio tab (page) as a background.

I've used vba a lot with other applications but never with Visio so even a place to start will help.
0
Comment
Question by:rogerdjr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Visio_Guy earned 500 total points
ID: 39634197
Hi Roger,

This isn't a perfect macro, and it doesn't deal with the file system, but it shows you how to create a page, import an image, and resize + center the image on the page.

There's plenty to learn from the sample, good luck!

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
  Call pg.Import("D:\Images\SomeImage.jpg")
  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
  Else
    f = 1 / fh
  End If
  
  '// 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"
  
  '// Cleanup:
  Set pg = Nothing
  Set shp = Nothing
  
End Sub

Open in new window

0
 

Author Closing Comment

by:rogerdjr
ID: 39634670
Awesome - works perfect and you are right, this will get me started with visio

Thanks a bunch!!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever created a custom Visio stencil – a collection of your own unique master shapes – and then created a drawing by dragging masters onto the drawing page? Have you then made changes to the stencil master and wondered why the shapes on the …
David Parker’s latest book, Microsoft Visio 2010: Business Process Diagramming and Validation, will give you the tools to turn flowcharts and other business diagrams into valuable, data-driven corporate assets. Armed with the knowledge you’ll gain f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question