does any one know if it is possible to connect to Visio with VB6?
Printable View
does any one know if it is possible to connect to Visio with VB6?
A) To do what?
B) Which version of Visio? (there are two major ones)
Yes, add the reference to your vb project, create an instance of visio
and do some automation etc.
Here is one way of doing it:
set references to Visio xxxx Type Library and run this sample code:
VB Code:
Private Sub Command1_Click() Dim vso As Visio.Application Set vso = New Visio.Application vso.Documents.Open "c:\temp\Test.vsd" vso.Visible = True Set vso = Nothing End Sub
Rob,
I didn't mean to cross post. :wave:
No prob. Don't hear that too often.
Thanks!
:D
I found one of my old projects on Visio. It shows how to set the
document properties through code as well as a few other things.
VB Code:
Option Explicit Dim VS As Visio.Application Dim VSD As Visio.Document Dim lPID As Long Private Sub cmdExit_Click() frmMain.Visible = False If TypeName(VS) <> "Nothing" Then If VS.Visible = True Then VS.Quit End If End If Set VS = Nothing Set VSD = Nothing Unload Me End Sub Private Sub cmdRun_Click() Set VS = New Visio.Application VS.Visible = True lPID = VS.ProcessID Set VSD = VS.Documents.Add(App.Path & "\VB.vst") VSD.Creator = "RobDog888" VSD.Company = "RobDog888" VSD.Title = "VB Visio Automation" VSD.Description = "Visual Basic automation of Microsoft Visio 2002" VSD.PrintLandscape = -1 VSD.Application.ActiveDocument.Pages(1) = "VB Visio-1" End Sub
ok so it is possible to connect to Visio and make a VB6 application. this is what i am trying to do, i need to know if it is possible to make a VB6 application that will access a Visio file and it will look for certain drawing numbers and put them into the visio file, but it has to be done through VB6.
i was looking in my references and i don't see the Visio library. if i don't have it do you know where i can get it?
It has to be installed on your development machine at least.
Although, I would check EULA for VISIO runtime files distribution procedure.
There are no redistributable visio runtimes. If you create an application that automates Visio, then the user's machine will have to have a licensed copy of Visio installed on it. There is no legal way around this ...Quote:
Originally posted by RhinoBull
It has to be installed on your development machine at least.
Although, I would check EULA for VISIO runtime files distribution procedure.
That said, I think that Microsoft might have some special integration licensing programs available for Visio, but I am almost certain that they wont be run time royalty free ... and I am certain that the standard Visio EULA has no provisions that allow redistribution.
This is all very much do-able. Take a stab at it and post the Visio and VB6 file and I can try to help if you want ...Quote:
Originally posted by Dubya007
ok so it is possible to connect to Visio and make a VB6 application. this is what i am trying to do, i need to know if it is possible to make a VB6 application that will access a Visio file and it will look for certain drawing numbers and put them into the visio file, but it has to be done through VB6.
ok thanx all. Muddy i will maybe have some thing some time later, just researching the possibilities right now.
Look at my code, it opens a drawing andQuote:
Originally posted by Dubya007
...make a VB6 application that will access a Visio file and it will look
for certain drawing numbers and put them into the visio file, but
it has to be done through VB6.
changes the page name. Instead of changing the name you could
check if it matches the page name in question and go from there.
Is that what you need?
VB Code:
VSD.Application.ActiveDocument.Pages(1) = "VB Visio-1" 'Change to something like this... If VSD.Application.ActiveDocument.Pages(1) = "TheDrawingNameIamLookingFor" Then 'Do something Else 'Do domething else Endif
kinda, i need to have a bunch of drawings on an sql server(is that possible?) and then be able to input a part number and it will bring up the drawings and put them all into a visio template.
but that all depends on if you can put a picture on an SQL server.
Yes, you can put a picture in a field of a record in SQL Server. I havent
done it, but I know its been asked here before. Try a search.
Beacon has a good tutorial regarding this. Download the attachment on the first post of the following thread:Quote:
Originally posted by RobDog888
Yes, you can put a picture in a field of a record in SQL Server. I havent
done it, but I know its been asked here before. Try a search.
http://www.vbforums.com/showthread.p...threadid=81916
For some reason, storing pictures in a database seems to be a controversial subject. I've seen a few heated threads making arguments against it, but I've never seen a good argument brought against the concept IMHO. I say go for it if it makes sense to you ... :-)
Muddy, I have seen those arguments also. They mainly center
around placing pictures in an Access database and not a SQL
Server. Access can do it but it is not scalable for many pictures.
Also if Access gets corrupt then you loose you pictures. SQL
Server does not get corrupt.
:D
i am at work and can not follow the link, so is there any way that you could show me the whole address of the link, i tried to copy and paste it but it doesn't work?
Robdogg you seem to know a lot about this stuff, is there a specific format i.e. jpg, tif, gif, bmp, that is better to be stored on an SQL server?
I would think the better format would be jpg or jpeg.
Code:http://www.vbforums.com/showthread.php?s=&threadid=81916
ok so now i can load a picture on to the SQL server how do i load the images into a picture box?
Doesnt Beacon's tutorial example do that too?Quote:
Originally posted by Dubya007
ok so now i can load a picture on to the SQL server how do i load the images into a picture box?
Beacons tutorial example doesn't show how to load pictures into the SQL Server. i found how to do load it into the SQL server some some place else. but it seems to be the same. here is the code.
that is how i have found to save a picture to an SQL server. the only problem is now i donno how to load the picture that is saved there to a an image box, or picture box in VB6. any ideas?VB Code:
Private Sub Command1_Click() Dim mystream As ADODB.Stream Set mystream = New ADODB.Stream mystream.Type = adTypeBinary mystream.Open mystream.LoadFromFile "H:\SAMDrawing\MountingW2Nameplates.bmp" With Rs .AddNew !ArresterNumber = Text1.Text !Drawing = mystream.Read .Update End With MsgBox "UPDATED AND WORKED" mystream.Close Set mystream = Nothing End Sub
ok i have the part done where i can save/retrieve images from the SQL server and i am working on the VB6 part to open Visio, i just need to be able to put the drawings in specific places in the Visio file. is it possible to put like a "Bookmark" into Visio?
I believe there is a way to position them, but not sure about bookmarks.
Let me look into it.
ok i will look into it as well. i think that it has to do with the different positions from the margins, i saw some thing to that effect in the help files.
How about using the .Drop method?
VB Code:
Example for Drop, Group 'This Microsoft Visual Basic for Applications (VBA) macro 'demonstrates dropping shapes using the Page, Document, 'and Shape objects. Public Sub Drop_Example () Dim shp1Obj As Visio.Shape Dim shp2Obj As Visio.Shape Dim shp3Obj As Visio.Shape Dim mstObj As Visio.Master Set shp1Obj = ActivePage.DrawRectangle(1, 2, 2, 1) Set shp2Obj = ActivePage.DrawRectangle(1, 4, 2, 3) 'Example of Page.Drop ActivePage.Drop shp1Obj, 3.5, 3.5 Set shp3Obj = ActivePage.Shapes(3) 'Example of Document.Drop - Creates a master Set mstObj = ActiveDocument.Drop(shp3Obj, 0, 0) 'Example of Shape.Drop ActiveWindow.DeselectAll ActiveWindow.Select shp1Obj, visSelect ActiveWindow.Select shp2Obj, visSelect ActiveWindow.Group Set shp1Obj = ActivePage.Shapes(2) shp1Obj.Drop shp3Obj, 3, 3 End Sub
Or the .Import method looks good too.
Quote:
Import method
Example
Imports a file into the application.
Version added: 3.0
Syntax:
objRet = object.Import(fileName)
objRet
A Shape object that represents the new shape imported from the file.
object
Required. An expression that returns the Page, Master, or Shape
object to receive the new shape.
fileName
Required String. The name of the file to import; must be a fully
qualified path.
Remarks:
The Import method imports the file specified by fileName onto a
page, or into a master or group.
The file extension indicates which import filter to use. If the filter
is not installed, the Import method returns an error. The Import
method uses the default preference settings for the specified
filter and does not prompt the user for non-default arguments.
Or even use the .PasteSpecial method.
Quote:
PasteSpecial method
Inserts the contents of the Clipboard, allowing you to control the
format of the pasted information and (optionally) establish a link
to the source file (for example, a Microsoft Word document).
Version added: 2002
Syntax
object.PasteSpecial (format [,link][,displayAsIcon])
object
Required. An expression that returns a Master, Page, or Shape object.
format
Required Long. The internal Clipboard format.
link
Optional Variant. True to establish a link to the source of the
pasted data; otherwise, False (the default). Ignored if the source
data is not suitable for, or doesn't support, linking.
displayAsIcon
Optional Variant. True to display the pasted data as an icon;
otherwise, False (the default).
Remarks
To simply paste the contents of the Clipboard into an object, use
the Paste method.
The PasteSpecial method of a Shape object works only with
Shape objects that are group shapes. Use the Type property of a
shape to determine whether it is a group.
The value of the format argument can be any of the following:
A value from VisPasteSpecialFormat (see the following table).
Any of the standard Clipboard formats, for example, CF_TEXT. For
details, see the Microsoft Platform SDK on the Microsoft Developer
Network (MSDN) Web site.
Any value returned from a call to the RegisterClipboardFormat
function. For details, see the Microsoft Platform SDK on the MSDN
Web site.
Possible values for format declared by the Visio type library in
VisPasteSpecialFormat are described in the following table.
Flag
Value
visPasteText
1
visPasteBitmap
2
visPasteMetafilePicture
3
visPasteOEMText
7
visPasteDeviceIndependentBitmap
8
visPasteEnhancedMetafile
14
visPasteOleObject
65536
visPasteRTF
65537
visPasteHyperlink
65538
visPasteURL
65539
so if a am using ADO to copy files to the c:\temp file then shouldn't i just load those pictures into the Visio Document?
Yes, the .Import method looks best. You can get the Shape reference
after you import one so you can make adjustments to it or ???
ok so i would put this code in the VB6 code window right?
VB Code:
'Fname is a variable for the string of the location of a file Dim shp1Obj As Visio.Shape Set shp1Obj = ActivePage.Import(FName)
i think that is what i need correct?
Looks right. Does it work for you though?
no sir. here is my code
this is the errorVB Code:
Private Sub cmdVisio_Click() Dim vso As Visio.Application Dim shp1Obj As Visio.Shape Set vso = New Visio.Application vso.Documents.Open "H:\SAMDrawing\SAMDraw\Test.vsd" vso.Visible = True Set shp1Obj = shp1Obj.Import(FName) Set vso = Nothing End Sub
object variable or with block not set
and it point to this line
Set shp1Obj = shp1Obj.Import(FName)
Ok, here is whats going on. You need to add the "shp1Obj" to
the drawing first to create an instance of a Shape object. Then
after its set you can modify its properties. Let me see if I can get
it to work.
Ok here it is.
VB/Outlook Guru!VB Code:
Private Sub cmdRun_Click() Dim vso As Visio.Application Dim vsd As Visio.Document Dim vsp As Visio.Page Dim shp1Obj As Visio.Shape Set vso = New Visio.Application Set vsd = vso.Documents.Open("H:\SAMDrawing\SAMDraw\Test.vsd") vso.Visible = True Set vsp = vsd.Pages.Item(1) 'Change to reflect the path to a image on your system Set shp1Obj = vsp.Import("D:\Development\work03.gif") shp1Obj.CenterDrawing End Sub
why would it tell me that i need to specify the type of file i am importing?
what references did you add to your project?
I added the reference: "Microsoft Visio 2002 Type Library (Service Release 1)"
ok i have the right reference. i get an error now that says visio can't open the file for reading.
Make sure its not being used by another instance of Visio.
If still not working, then try saving your project and rebooting
your system. Then try. Maybe there is a process still attached to
the drawing from any previous debugging?
ok i will give that a shot. here is the code for my whole thing maybe something in there has some thing to do with it.
VB Code:
Option Explicit Public Rs As New ADODB.Recordset '****************************************** 'this is sub is for getting the pics 'off of the DB Private Sub cmdGet_Click() Dim Srs As ADODB.Recordset Set Srs = New ADODB.Recordset Dim sql As String ArrestNum = UCase(InputBox("Enter Arrester Number", "Arrester number")) sql = "SELECT * FROM Drawing WHERE ArresterNumber = '" & ArrestNum & "'" Srs.Open sql, DBConn, adOpenDynamic, adLockOptimistic Dim mstream As ADODB.Stream Set mstream = New ADODB.Stream 'mystream is binary because it will be retrieved as a binary from the DB mstream.Type = adTypeBinary mstream.Open 'the caption that goes with the picture is loaded into label1 Label1.Caption = CStr(Srs.Fields("ArresterNumber").Value) 'The stream is "writing" what is in the Drawing field of the table mstream.Write Srs.Fields("Drawing").Value 'the stream saves it to a temporary file mstream.SaveToFile "C:\Temp.jpg", adSaveCreateOverWrite 'Image1 laods the picture from the temporary file Image1.Picture = LoadPicture("C:\Temp.jpg") FName = "C:\Temp.jpg" 'The file is then destroyed as it is no longer needed Kill ("C:\Temp.jpg") mstream.Close Set mstream = Nothing Srs.Close Set Rs = Nothing End Sub '********************************************* 'This sub is for loading a picture from 'a saved location on the network i.e. a folder Private Sub cmdLoadFile_Click() With Dialog .DialogTitle = "Select Picture to Open........." .ShowOpen FName = .FileName Image1.Picture = LoadPicture(.FileName) End With End Sub '******************************************* 'This sub is for saving the pics to the DB Private Sub cmdSave_Click() Dim sql As String 'ArrestNum is capitalized so that retrieving will be smoother ArrestNum = UCase(InputBox("Enter Picture Name", "Name this Picture")) sql = "SELECT * FROM Drawing" Rs.Open sql, DBConn, adOpenDynamic, adLockOptimistic Dim mystream As ADODB.Stream Set mystream = New ADODB.Stream 'mystream is binary because it will be saved as binary in the DB mystream.Type = adTypeBinary mystream.Open 'adding a new record With Rs .AddNew 'The caption for the picture !ArresterNumber = ArrestNum 'loads the picture from the file into mystream Debug.Print FName mystream.LoadFromFile FName 'reads the picture into the Drawing field of the DataBase and updates the DB !Drawing = mystream.Read .Update End With MsgBox "UPDATED AND WORKED" mystream.Close Set mystream = Nothing Rs.Close Set Rs = Nothing End Sub Private Sub cmdVisio_Click() Dim vso As Visio.Application Dim vsd As Visio.Document Dim vsp As Visio.Page Dim shp1Obj As Visio.Shape Debug.Print FName Set vso = New Visio.Application Set vsd = vso.Documents.Open("H:\SAMDrawing\SAMDraw\Test.vsd") vso.Visible = True Set vsp = vsd.Pages.Item(1) 'Change to reflect the path to a image on your system Set shp1Obj = vsp.Import("H:\SAMDrawing\MountingW2Plates.bmp") shp1Obj.CenterDrawing '"H:\SAMDrawing\MountingW2Plates.gif" End Sub '*************************************** 'The form loads with a connection the DB Private Sub Form_Load() Call makeConnection End Sub
i tried it out and it didn't work. so i don't think that it has any thing to do with my other code. i'm still trying to figure some thing else out.
I dont think any of the other code is affecting the Visio part, but
what is the exact version you are running? I am running 2002 SP-2
10.0.5110. I tried my code with a .bmp file on a network share
and it still worked.
:confused:
Maybe it has something to do with the image not being accessible
or maybe its not finished being loaded from the other procedure
which retrieves the image from the db.
i am using Visio 2000 6.0.0.3 so your are way more current than me. i have tried to "Hardwire" the picture in there that way none of my other code will have any affect on it. i have to get pics off the DB, but i figured that i should first learn to put pics in there with VB6 first then try to get them off the DB.
i've been working with it a little more and have discovered some thing rather interesting.
when i try to import a bitmap(bmp) then i get an error saying
"Visio can't open the file for reading"
but when i try to open a JPEG(jpg) or a GIF(gif) i get an error saying
"An Error occured. Visio is unable to complete importing"
Try using an image from your system that is not being pulled out
from the database. It may be that there could be a process still
on the image being pulled from the db. Just use a samlpe picture
like your desktop wallpaper or anything else and see if it works.
that is what i have been using. in the future i will try and get them from the DB, but now i am just hardwiring the value in the program
Set shp1Obj = vsp.Import("H:\SAMDrawing\MountingW2Plates.bmp")
Instead of using a mapped drive, try using a copy of the picture
on your C drive. It must be something specific to Visio 2k?
i got the same error, changed it to a pic on the C: drive. i have been looking @ the help files all morning long and i still have not found any thing.
Try doing an Office Update to see if there is a hotfix or sp for Visio 2k.
It has to be something because the code works fine in 2002.
:confused:
i'll see what i can do about that, i am only on a small node and can't do that stuff i think, let me look tho. if not i think maybe i'll have to try the drop method.
is this how i would tell if i need a hotfix or sp?
No, use the office update website. Its the same as windows update
but for office. Click on "Check for Updates" link to start.
Office Update
i went the website but i can not follow the link to the officeupdate because i am @ work. so do you think that you could post the address not as a hyperlink?
Code:http://office.microsoft.com/search/redir.aspx?AssetID=ES790020331033&Origin=HH011497461033&CTT=5
k i looked and there weren't any that were needed for Visio. there were some other things in there but nothing about Visio.
do you think that it is because i am using ado in the program?
??? But even I came up with one for Visio XP.
Visio 2002 Security Update: KB831932