Solved

How to write "Export" routine to a excel file from Visio using VBA in Access

Posted on 2011-02-18
12
1,309 Views
Last Modified: 2013-11-27
Hi! I'm trying using VBA in Access to :
1) export employee table to excel and open Visio (done!!!);
after the updating  organization structure  chart in Visio (as usual!);
3) in Access save the organization chart uptdated in Visio and  export the organization chart to excel file
4) import the excel file in access table (done!!!).

Someone has some experience about point 3)? (i'm able in Visio VBA to save some fields of the
organization  chart in a excel file but i need to have the list of the main fields name too!)
thanks a lot
 
0
Comment
Question by:giorgiorossanigo
[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
  • 7
  • 5
12 Comments
 
LVL 30

Expert Comment

by:Scott Helmers
ID: 34933034
You may have already found this article: http://office.microsoft.com/en-us/visio/HA010774641033.aspx
It doesn't help with exporting the org chart but may provide some assistance. If you want to see VBA code that uses the info from that article, see this EE article.

I haven't found a comparable way to export the Visio org chart from VBA. You could use 'SendKeys' -- it's not elegant but it would work. The key sequence is
  Alt+C
  X
  <filename>
  Enter

Alt+C opens the Org Chart menu; X is for Export, which opens a Save As dialog; then provide the filename and press enter.

Important note: if you have Visio 2010, use Alt+O instead of Alt+C
0
 

Author Comment

by:giorgiorossanigo
ID: 34934154
Thanks a  lot Scoot!!! now let me study your proposal.......
0
 

Author Comment

by:giorgiorossanigo
ID: 34934324
Scott, your solution could be powerfull...but how i can tell to the code (in my VBA code in Access) that i want to use these keys in Visio application?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Scott Helmers
ID: 34934394
I was referring to the VBA SendKeys method. This should help:
   http://msdn.microsoft.com/en-us/library/aa202943%28office.10%29.aspx

Be sure to look a the bottom of the article to see how to include the Alt key.

Let me know if you need further assistance.
0
 

Author Comment

by:giorgiorossanigo
ID: 34934430
Hi Scott!
no problem in order to write the right code for Alt key...but...the SenKey "Sends keystrokes to the active application"...but i'm in Acess VBA routine...so i think that actual application is Access e not Visio! how i can tell to my VBA cose that i want to use the Keys in Visio environmnet?
Thanks!!!
0
 
LVL 30

Expert Comment

by:Scott Helmers
ID: 34934457
I presume you've already created an object to refer to the Visio application? You must have done that because you said you open Visio from Access in step 1. Use SendKeys on that object, e.g., if your Visio app is vsoApp, then
   vsoApp.SendKeys("%fC")
0
 
LVL 30

Expert Comment

by:Scott Helmers
ID: 34934488
I'm sorry -- I may have misled you. It doesn't look like the Visio application object takes the SendKeys method. Stay tuned...
0
 

Author Comment

by:giorgiorossanigo
ID: 34934523
Scott......help me!
Sorry...but my code isn't working!! ....."no property supported........"
This is my code in Access:  the error occurs in " objVisio.SendKeys ("%4") " line

Private Sub Comando14_Click()
DoCmd.SetWarnings False
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    'Kill the prevoius file if it exist
    If Dir("C:\Users\Giorgio rossanigo\Documents\SocietàVisio.xlsx") <> "" Then
        Kill ("C:\Users\Giorgio rossanigo\Documents\SocietàVisio.xlsx")
    End If

DoCmd.OpenQuery "SocietàperVisio"          'run the query that create data for excel
DoCmd.TransferSpreadsheet acExport, , "SocietàVisio", "C:\Users\Giorgio rossanigo\Documents\SocietàVisio.xlsx", True       ' create the file excel for visio


Dim objVisio As Object

Dim strCommandPart As String

'START THE ORG CHART WIZ
Set objVisio = CreateObject("Visio.Application")
Set objAddOn = objVisio.Addons.ItemU("OrgCWiz")
objAddOn.Run ("/S-INIT")
strCommandPart = "/FILENAME = C:\Users\Giorgio rossanigo\Documents\SocietàVisio.xlsx / ID_Univoco - Field = ID_Univoco / Nome - Field = Nome /Subordinato_a - Field = Subordinato_a / Shape - Field = Master_Shape / Update - Shapes - OnOpen"
objAddOn.Run ("/S-ARGSTR " + strCommandPart)

objAddOn.Run ("/S-RUN")
objVisio.Application.ActiveWindow.ShowGrid = False


Msg = "confermi le modifiche effettuate nel disegno della struttura organizzativa?"    ' Definisce il messaggio. "do you confirm the updats?"
                                                                    Style = vbYesNo + vbQuestion + vbDefaultButton2
                                                                    Title = "Conferma"
                                                                    Ctxt = 1000
                                                                    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
                                                                     
                                                                                     If Response = vbNo Then                  'Close Visio
                                                                                       
                                                                                        objVisio.ActiveDocument.Saved = True
                                                                                        objVisio.Quit
                                                                                       
                                                                                     Else
                                                                                        '-----------------------------------------------------------
                                                                                        'DoCmd.Hourglass
                                                                                           
                                                                                            objVisio.SendKeys ("%4") ' because i have my custom menu!!!
                                                                                       
                                                                                            objVisio.SendKeys ("~RitornoSocietàVisio.xlsx")
                                                                                        '------------------------------------------------------------
                                                                                        objVisio.ActiveDocument.Saved = False
                                                                                        objVisio.Quit
                                                                                     End If






End Sub

0
 
LVL 30

Expert Comment

by:Scott Helmers
ID: 34934573
See my previous posting. I thought Visio supported sendkeys but apparently not. I must remember using with some other app. I won't be able to get back to this until sometime tomorrow. I'll see what else I can come up with that will work.
0
 

Author Comment

by:giorgiorossanigo
ID: 34934651
Scott, thanks a lot for your help!!!!!!!!!!
0
 

Accepted Solution

by:
giorgiorossanigo earned 0 total points
ID: 34958595
I solved the problem!!!  definitely! I can design and redesign organization chart using Access database and update the Access database based on updated organization chart automatically
If someone wants to know how, please contact me!
0
 

Author Closing Comment

by:giorgiorossanigo
ID: 34990915
It's working!!!!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

717 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