Naming a new master

J

John

Hi,

I'm trying to create a procedure that will import an image file as a master
and then place it on a number of background pages. The placing bit I'm
happy with, but I'm having trouble with refering to the master once it's in
the document stencil. I'm trying to name it "Logo" so I can then refer to
it more easily than a number ("Master.12" for instance).

It's the last two lines that appear to be the problem. Can anyone tell me
where I'm going wrong??

Thanks in advance

Regards

John


Sub ImportImage()

Dim docObj As Visio.Document
Dim newLogoMstr As Visio.Master
Dim logoFile As String
Dim logoShp As Visio.Shape
Dim mastersObj As Visio.Masters
Dim logoName As String

logoName = "Logo"

logoFile = "C:\Image.wmf"

Set docObj = ActiveDocument

Set mastersObj = docObj.Masters

newLogoMstr = mastersObj.Add.Import(logoFile)
newLogoMstr.Name = logoName
 
C

Chris Roth [ Visio MVP ]

If you break it up into more steps, ie: "add a master", then "import image",
it works. Here's some VBA code:

Dim mst As Visio.Master
Dim msts As Visio.Masters

Set msts = ThisDocument.Masters
Set mst = msts.Add

mst.NameU = "Almdudler" ' NameU is the "real, non-localized name"
mst.Import ("D:\System Shared\Desktop\Almdudler.jpg")

' Check here to see if NameU is still what you assigned, or
' if Visio automagically gave it a ".2", ".3", etc.
Debug.Print mst.NameU

--

Hope this helps,

Chris Roth
Visio MVP
 
J

John

Chris,

Thanks for this. This works great. I'm still not quite clear on when you
should use "Set" and when you can just write the variable = "x". Is this
something to do with the first time that the variable is set and then all
subsequent changes or instances can be just written out?

Anyway, my next issue is printing, but I'll leave that to a new post.

Thanks again.

John
 
C

Chris Roth [ Visio MVP ]

Set is for Visual Basic only, and is used when setting objects.

You don't need Set for primitive data types strings, integers, doubles, etc.

Luckily in VB.NET Set goes away. Yeah!

--

Hope this helps,

Chris Roth
Visio MVP
 
J

John

Thanks Chris. I've just bought the Beginning VB.NET 2003 book, so maybe
that's where I'm picking up bad habits!

Thanks again for your help.

Regards

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top