运行时错误462:远程服务计算机不存在或不可用“,从Excel到MS Project

时间:2018-05-21 13:36:18

标签: excel-vba ms-project vba excel

下午好,

我正在运行一个代码,该代码从主MS Excel工作簿开始,然后将数据传输到中间Excel文件,然后传输到MS Project文件。

一旦脚本启动,它就会要求用户从8个不同的类别中选择一个类别,一旦做出选择,脚本会将主Excel链接到几个Excel-MS Project文件,并在那里加载数据。

Dim wbAp As Workbook
Dim wb1 As Workbook

Set wb1 = ActiveWorkbook
Dim ws As Worksheet
Dim ws1 As Worksheet

Dim Task As String
Dim t As Task
Dim exStartDate As Date

Dim task_counter As Integer
Dim status As Integer

Dim prApp As MSProject.Application
Dim prProject As MSProject.Project
Dim projectField As Long

Set prApp = CreateObject("MsProject.Application")

answer_clus = InputBox("What do you want to see?)
    If answer_clus = "1" Then
    selection_variable = "INSTALLATION EQUIPMENT"
    Set wbAp = Workbooks.Open("C:\Users\Desktop\File1.xlsx")
    prApp.FileOpen "C:\Users\Desktop\File1.mpp"
    Set prProject = prApp.ActiveProject
ElseIf answer_clus = "2" Then
    selection_variable = "PIPELAYING EQUIPMENT"
    Set wbAp = Workbooks.Open("C:\Users\Desktop\File2.xlsx")
    prApp.FileOpen "C:\Users\Desktop\File2.xlsx"
    Set prProject = prApp.ActiveProject

上面有一个例子。选择的总数是8,但为了简洁起见,我只写了2,其他都是一样的。

问题是,我第一次选择其中一个替代方案时,脚本会加载中间Excel文件,但是,一旦到达MS Project,它就会给我运行时错误462。 如果我用相同的选择重新运行vba脚本,它工作正常,所以问题不是绝对的,我仍然能够获得所需的输出,但它很烦人,因为我必须运行两次相同的脚本(并且它是耗时的。)

有没有人有解决方案?

非常感谢你, 安德烈

0 个答案:

没有答案