Results 1 to 2 of 2

Thread: Excel VBA to Open Visio template Search and replace string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Location
    Newark-on-trent, Nottingham
    Posts
    243

    Excel VBA to Open Visio template Search and replace string

    Hi I want to open a Visio document template from within my Excel spreadsheet and search and replace set values with values from my Excel spreadsheet.

    For Example Cell M33 contains the Customer Name and I want to open the file Visio_template.vsd and find and replace the string [Customer] with the value of cell M33.

    Code:
    Dim VisioApp As Object
    vfilepath = Application.ActiveWorkbook.Path
    Set objv = CreateObject("Visio.Application")
    objv.Visible = True
    For the next bit I did the very same thing as i have working for a Word document...
    Code:
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.documents.Open(seedsdd)
    Set objSelection = objWord.Selection
    Const wdReplaceAll = 2
    
    ' Customer Name
    
    objSelection.Find.Text = "[Customer]"
    objSelection.Find.Forward = True
    objSelection.Find.MatchWholeWord = True
    objSelection.Find.Replacement.Text = Worksheets("Calculator").Range("M" & 33).Value
    objSelection.Find.Execute , , , , , , , , , , wdReplaceAll
    How do I achieve this in a Visio document?

    Thanks

    Steve

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Location
    Newark-on-trent, Nottingham
    Posts
    243

    Re: Excel VBA to Open Visio template Search and replace string

    As is often the case through persistence I managed to answer my own question eventually so for anyone ese that stumbles across this post in the future with the same problem here is how i did it...


    Code:
    Dim AppVisio As Object
        Dim oCharacters As Object
        Dim lX As Long
        Dim sChar As String
        
        Set AppVisio = CreateObject("visio.application")
        AppVisio.Visible = True
        Set objdoc = AppVisio.Documents.Open(seedsdd)
        
            
    ' Find [Customer]
    For Each vsoPage In objdoc.Pages
            For Each vsoShape In vsoPage.Shapes
                Set vsoCharacters1 = vsoShape.Characters
                vsoStrng = Worksheets("Calculator").Range("M" & 33).Value
                vsoCharacters1.Text = Replace(vsoCharacters1.Text, "[Customer]", vsoStrng)
            Next
        Next

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width