Excel VBA中的错误462,如何防止它发生?

时间:2015-08-06 17:29:00

标签: excel vba object ms-word runtime-error

我之前发表了一篇关于此代码here的帖子,现在我的代码正常运行,我正在制作一个bug。我可以运行代码一次很好和花花公子,但如果我尝试第二次使用不同的值运行代码我得到"运行时错误462:机器服务器不存在或无法找到"

我在MS Supporthere上进行了一些搜索,这让我了解了我应该修复的内容,但我担心我只是不知道该怎么做。了解我需要做什么。

以下是代码:

Private Sub CommandButton2_Click()
'
' Creates a new checksheet for the selected fixture data
'
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True

    ActiveCell.Select
    Selection.Copy

Documents.Add Template:="C:\Users\det10\Documents\Custom Office Templates" _
 & "\FSPC_Template3.dotx"
'
' Change this address to the proper storage location upon rollout
'
    With wdApp

        .Selection.Goto What:=wdGoToBookmark, Name:="Fixture_Number"
        .Selection.PasteAndFormat (wdFormatPlainText)
        .Visible = True
        ActiveDocument.SaveAs2 Filename:=ActiveCell.Text

    End With

ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="C:\Users\det10\Documents\" & ActiveCell.Text & ".docx"

'
' Change the hyperlink address to the correct location upon rollout
'
End Sub

我认为我应该将文档设置为对象或类似的东西,但我不明白为什么,到目前为止我还没有能够用它做任何事情。

0 个答案:

没有答案