Excel的VBAmacros执行使用DDE打开数据源的邮件合并

我想使用macros来执行从同一个Excel工作簿运行的邮件合并。我需要使用DDE作为数据源,因为我想保持格式。 但是,这个macros运行永远终于冻结了我的屏幕。 我不知道macros中是否有问题。 谢谢!

Sub RunMerge()

Dim wd As Object Dim wdocSource As Object Dim strWorkbookName As String On Error Resume Next Set wd = GetObject(, "Word.Application") If wd Is Nothing Then Set wd = CreateObject("Word.Application") End If On Error GoTo 0 Set wdocSource = wd.Documents.Open("P:\trial.docx") strWorkbookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name wdocSource.Mailmerge.MainDocumentType = wdFormLetters wdocSource.Mailmerge.OpenDataSource _ Name:=strWorkbookName, _ SubType:=wdMergeSubTypeWord2000, _ AddToRecentFiles:=False, _ Revert:=False, _ Format:=wdOpenFormatAuto, _ Connection:=`Sheet1$` & ";Mode=Read", _ SQLStatement:="SELECT * FROM `Sheet1$`" With wdocSource.Mailmerge .Destination = wdSendToNewDocument .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=False End With wd.Visible = True wdocSource.Close SaveChanges:=False Set wdocSource = Nothing Set wd = Nothing 

结束小组