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.