Sub prt()
'先要在工具中引用ADO
'把要换的文本内容保存在excel第1列中,有字段名
Dim con As ADODB.Connection
Set con = New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim str As String
str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\文本.XLSX;Extended Properties=Excel 12.0;Persist Security Info=False"
con.Open str
rs.Open "SELECT * FROM [SHEET1$]", con, adOpenKeyset, adLockOptimistic
'最后一个放入的文本框:vsoCharacters1
Dim i As Integer
i = Application.ActiveWindow.Page.Shapes.Count
Dim vsoCharacters1 As Visio.Characters
Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(i).Characters
Do While Not rs.EOF
With vsoCharacters1
.Begin = 0
.Text = rs(0)
End With
Application.ActiveDocument.PrintOut PrintRange:=visPrintAll
rs.MoveNext
Loop
rs.Close
con.Close
End Sub