Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visio 2013

Posted on 2013-11-07
2
Medium Priority
?
698 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 2000 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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…
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article we’ll examine containers. We’ll explore lists (http://www.experts-exchange.com/Microsoft/Applications/M…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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