Dav*_*ton 5 merge microsoft-visio
我知道我可以通过使用复制/粘贴来手动执行此操作,但我正在寻找一种更简单的方法。
有谁知道一种快速简便的合并 Visio 文档的方法?我有几个 Visio vsd 文件,它们都是相同的内部文档类型(流程图 - 美国单位)。每一个都有 1 到 15 页。我想将它们全部合并到一个 Visio 文件中。
我正在使用 Visio for Enterprise Architects (11.4301.8221),因此如果在该版本中有执行此操作的程序,这就是我正在寻找的,但是 3rd 方工具或宏也可以使用。
这不容易做到,因为 Visio 没有在 Visio 中的页面对象上提供一个很好的 .Copy 方法。
这可以通过 VBA 来完成,但它并不像我认为的那样简单。
我将在下面粘贴一些 VBA 代码,您可以通过传递一个文件名数组来使用这些代码,这些文件名将复制到每个文档的所有页面中。但是请注意,它不会复制任何页面级 shapesheet 值,因为这对我来说现在太复杂了......所以如果你只是复制形状,这应该适合你(TryMergeDocs sub 是我用来测试这个的,它似乎运行良好)...
Private Sub TryMergeDocs()
Dim Docs() As Variant
Docs = Array("C:\Tmp\JunkVSD\Drawing1.vsd", "C:\Tmp\JunkVSD\Drawing2.vsd", "C:\Tmp\JunkVSD\Drawing3.vsd")
MergeDocuments Docs
End Sub
Sub MergeDocuments(FileNames() As Variant, Optional DestDoc As Visio.Document)
' merge into a new document if no document is provided
On Error GoTo PROC_ERR
If DestDoc Is Nothing Then
Set DestDoc = Application.Documents.Add("")
End If
Dim CheckPage As Visio.Page
Dim PagesToDelete As New Collection
For Each CheckPage In DestDoc.Pages
PagesToDelete.Add CheckPage
Next CheckPage
Set CheckPage = Nothing
' loop through the FileNames array and open each one, and copy each page into destdoc
Dim CurrFileName As String
Dim CurrDoc As Visio.Document
Dim CurrPage As Visio.Page, CurrDestPage As Visio.Page
Dim CheckNum As Long
Dim ArrIdx As Long
For ArrIdx = LBound(FileNames) To UBound(FileNames)
CurrFileName = CStr(FileNames(ArrIdx))
Set CurrDoc = Application.Documents.OpenEx(CurrFileName, visOpenRO)
For Each CurrPage In CurrDoc.Pages
Set CurrDestPage = DestDoc.Pages.Add()
With CurrDestPage
On Error Resume Next
Set CheckPage = DestDoc.Pages(CurrPage.Name)
If Not CheckPage Is Nothing Then
While Not CheckPage Is Nothing ' handle duplicate names by putting (#) after the original name
CheckNum = CheckNum + 1
Set CheckPage = Nothing
Set CheckPage = DestDoc.Pages(CurrPage.Name & "(" & CStr(CheckNum) & ")")
Wend
CurrDestPage.Name = CurrPage.Name & "(" & CStr(CheckNum) & ")"
Else
CurrDestPage.Name = CurrPage.Name
End If
On Error GoTo PROC_ERR
Set CheckPage = Nothing
CheckNum = 0
' copy the page contents over
CopyPage CurrPage, CurrDestPage
End With
DoEvents
Next CurrPage
DoEvents
Application.AlertResponse = 7
CurrDoc.Close
Next ArrIdx
For Each CheckPage In PagesToDelete
CheckPage.Delete 0
Next CheckPage
PROC_END:
Application.AlertResponse = 0
Exit Sub
PROC_ERR:
MsgBox Err.Number & vbCr & Err.Description
GoTo PROC_END
End Sub
Sub CopyPage(CopyPage As Visio.Page, DestPage As Visio.Page)
Dim TheSelection As Visio.Selection
Dim CurrShp As Visio.Shape
DoEvents
Visio.Application.ActiveWindow.DeselectAll
DestPage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).Formula = CopyPage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).ResultIU
DestPage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageWidth).Formula = CopyPage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageWidth).ResultIU
Set TheSelection = Visio.ActiveWindow.Selection
For Each CurrShp In CopyPage.Shapes
TheSelection.Select CurrShp, visSelect
DoEvents
Next
TheSelection.Copy visCopyPasteNoTranslate
DestPage.Paste visCopyPasteNoTranslate
TheSelection.DeselectAll
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33087 次 |
| 最近记录: |