Automate Drawing and Saving with Linked Data

Started by jatwork, February 27, 2017, 08:20:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jatwork

So I've been digging though the forum here and elsewhere on the interwebs and have found some related things, but nothing quite like what I'd like to do. If there is already something here I apologize.

I have created a custom shape stencil that populates with text from linked Excel data when I manually drag it from the list. I'm working on a solution for circuit flow diagrams and hope to make things easier by creating drawings automatically based on each row in my spreadsheet. Currently I drag the data from a row to the shape which populates with the data, then I save the drawing and repeat till I'm at the end of the sheet.

What I'd like to happen is that I fill out my spreadsheet, open my Visio template, link the Excel data to the Visio drawing, hit RUN and have 50 drawings made from the data saved with a filename pulled from one of the Shape Data entries(the DrawTitle entry).

It was hard enough to get the stencil and linked data to do what I wanted, so this VBA stuff is way over my head haha. If anyone could help me out with some hints, sample code or point me in the right direction, I'd really appreciate it. If you can write something up that does it all, that'd be even better!

FYI, I'm currently stuck with Visio 2010 Professional. If all that doesn't make any sense, let me know and I'll try to clarify! I've attached a template with some example data already linked in to show what I'm starting with...

Thanks!
j


*******EDIT********
I now know that this is probably the wrong subforum for this question, but thought I'd post what I ended up with that is working.
See my thread in Programming and Code section for a little background

Sub LinkDataSaveFile()

    Dim vsoDataRecordset As Visio.DataRecordset
    Dim intCount As Integer
    Dim lngRowIDs() As Long
    Dim lngRow As Long
    Dim vsoShp As Shape
    Dim FName As Variant
    Dim FPath As String

    intCount = ThisDocument.DataRecordsets.Count
    Set vsoDataRecordset = ThisDocument.DataRecordsets(intCount)
    lngRowIDs = vsoDataRecordset.GetDataRowIDs("")

    'Iterate through all the records in the data recordset.
    For lngRow = LBound(lngRowIDs) + 1 To UBound(lngRowIDs) + 1
       
        'links data from row to drawing
        ActivePage.Shapes.ItemFromID(1).LinkToData vsoDataRecordset, lngRow
        Set vsoShp = ActivePage.Shapes.ItemFromID(1)
        FName = vsoShp.CellsU("Prop._VisDM_DrawTitle").ResultStr(Visio.visNone)
        FPath = "C:\Visio Files\autosave\"
        ThisDocument.SaveAs FileName:=FPath & FName & ".vsd"
        Application.ActiveDocument.ExportAsFixedFormat visFixedFormatPDF, FPath & "PDFS\" & FName & ".pdf", visDocExIntentPrint, visPrintAll
        Debug.Print "Complete! - "; FPath; FName; ".vsd"

    Next lngRow
End Sub