0

I made a post earlier about this code here and now that I have the code working I am working out a bug. I can run the code once fine and dandy, but if I try to run the code a second time with a different value I get "runtime error 462: machine server doesn't exist or cannot be found"

I did some searching on MS Support and here, which gave me an idea of what I'm supposed to be fixing, but I'm afraid I just don't understand what I need to do.

Here's the code:

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

I think I'm supposed set Documents as an object or something like that, but I don't understand why and so far I have not been able to do anything with it.

Community
  • 1
  • 1
Derek
  • 1
  • 3
  • 1
    `wdApp.Documents.Add Template:= ...` also `.ActiveDocument.SaveAs2...` Any time you're referring to something connected to Word you need to make sure you qualify it with `wdApp` – Tim Williams Aug 06 '15 at 17:36
  • Looks like that solved the problem, thank you! So by adding `wdApp` to the `Add Template` command that specifically tells the program to do that command in Word? And then the extra `.` in front of `ActiveDocument` is basically just specifying that it's part of that `With` statement, right? I'm really happy it works now, but I also want to make sure I'm understanding this correctly. – Derek Aug 06 '15 at 17:49

0 Answers0