excelcopy-pastevisio

How to copy text in Excel and PasteSpecial to VISIO using VBA?


I try to copy text form Excel and paste using PasteSpecial but it show error "Run-time error 438" at visApp.ActiveWindow.PasteSpecial 3

Sub CopyTextFromExcelToVisio()
Dim visApp As Object
Dim visDoc As Object
Dim copyRange As Object
Dim visPage As Object
Dim destpage As Integer

Set visApp = CreateObject("Visio.Application")

Set visDoc = visApp.Documents.Open("PATH")

Set copyRange = ThisWorkbook.Sheets("ToVISIO").Range("A1:B31")

copyRange.Copy

destpage = 8
Set visPage = visDoc.Pages(destpage)

visApp.ActiveWindow.Page = visPage
visApp.ActiveWindow.PasteSpecial 3

Set visDoc = Nothing
Set visApp = Nothing
End Sub

Please tell me how to solve it? T T


Solution

  • visApp.ActiveWindow.PasteSpecial 3

    Window object (Visio) have not PasteSpecial method!
    You need use Page object and its Page.PasteSpecial method

     ' visApp.ActiveWindow.PasteSpecial 3  'change this line to next line
     visPage.PasteSpecial 3