| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2387 人关注过本帖, 1 人收藏
标题:远程服务器不存在或不能使用
只看楼主 加入收藏
zhulei666
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2018-5-19
结帖率:50%
收藏(1)
已结贴  问题点数:20 回复次数:9 
远程服务器不存在或不能使用
VB操作EXCEL打印,赋值,给赋值的单元格加边框,第一遍顺利,执行第二遍时,在给单元格赋值语句停止,提示 远程服务器不存在或不能使用,错误代码462
重新关闭程序,再启动,还是只能执行一遍。度娘上所有方法都尝试,均无效。跪求答案!

[此贴子已经被作者于2018-5-19 10:14编辑过]

搜索更多相关主题的帖子: 远程 服务器 存在 赋值 单元格 
2018-05-19 10:11
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
收藏
得分:0 
可能是execl没有正常关闭,或者关闭顺序不对。

2018-05-19 14:26
zhulei666
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2018-5-19
收藏
得分:0 
excel所有关闭顺序都实验了,还是没有解决。多谢大哥,再替我想想
2018-05-19 16:18
zhulei666
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2018-5-19
收藏
得分:0 
                       Dim xlapp As New Excel.Application
                       Dim xlbook As New Workbook
                    
                      Set xlapp = CreateObject("Excel.Application") '创建EXCEL对象
                                   
                      Set xlbook = xlapp.Workbooks.Open("e:\shujuku\zggddy.xlsx") '打开已经存在的EXCEL工件簿文件
                      xlapp.Visible = True '设置EXCEL对象可见(或不可见)
                      Set xlsheet = xlbook.Sheets("sheet1")  '设置活动工作表
                                          
                      Adodc1.Recordset.MoveFirst
                     
                      Do While Not Adodc1.Recordset.EOF
                                                xlapp.Cells(i, 1) = Adodc1.Recordset.Fields(0)
                                                xlapp.Cells(i, 2) = Adodc1.Recordset.Fields(1)
                                                xlapp.Cells(i, 3) = Adodc1.Recordset.Fields(2)
                                                xlapp.Cells(i, 4) = Adodc1.Recordset.Fields(3)
                                                xlapp.Cells(i, 5) = Adodc1.Recordset.Fields(4)
                                                xlapp.Cells(i, 6) = Adodc1.Recordset.Fields(5)
                                                xlapp.Cells(i, 7) = Adodc1.Recordset.Fields(6)
                                                xlapp.Cells(i, 8) = Adodc1.Recordset.Fields(7)
                                                xlapp.Cells(i, 9) = Adodc1.Recordset.Fields(8)
                                                xlapp.Cells(i, 10) = Adodc1.Recordset.Fields(9)
                                                
                                                Adodc1.Recordset.MoveNext
                                                i = i + 1
                       Loop
                        第二次执行都是下面这句报警。上面的都能执行。第一次执行下面这句也能通过。                         
                       With xlapp.Range(Cells(4, 1), Cells(3 + n, 10)).Borders
                             .LineStyle = 1
                             .Weight = 2
                       End With
                    
                       isok = MsgBox("确认打印内容是否正确", vbYesNo + vbQuestion)
                       
                       
                       If isok = vbYes Then
                                    
                                
                                    Set xlsheet = Nothing
                                    xlbook.Close (True) '关闭工作簿
                                    Set xlbook = Nothing
                                    xlapp.Quit '结束EXCEL对象
                                    Set xlapp = Nothing '释放xlApp对象
                                    Command2.Visible = True
                    
                       Else
                                    xlbook.Close (True) '关闭工作簿
                                    Set xlbook = Nothing
                                   xlapp.Quit '结束EXCEL对象
                                   Set xlapp = Nothing '释放xlApp对象
                                    Kill ("E:\shujuku\zggddy.xlsx")
                                   
                       End If
2018-05-19 16:22
zhulei666
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2018-5-19
收藏
得分:0 
  Do While Not Adodc1.Recordset.EOF
                                                xlapp.Cells(i, 1) = Adodc1.Recordset.Fields(0)
                                                With xlapp.Cells(i, 1).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                               
                                                xlapp.Cells(i, 2) = Adodc1.Recordset.Fields(1)
                                                With xlapp.Cells(i, 2).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                
                                                xlapp.Cells(i, 3) = Adodc1.Recordset.Fields(2)
                                                With xlapp.Cells(i, 3).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                                                                  
                                                xlapp.Cells(i, 4) = Adodc1.Recordset.Fields(3)
                                                With xlapp.Cells(i, 4).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                
                                                xlapp.Cells(i, 5) = Adodc1.Recordset.Fields(4)
                                                With xlapp.Cells(i, 5).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                xlapp.Cells(i, 6) = Adodc1.Recordset.Fields(5)
                                                With xlapp.Cells(i, 6).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                
                                                xlapp.Cells(i, 7) = Adodc1.Recordset.Fields(6)
                                                 With xlapp.Cells(i, 7).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                xlapp.Cells(i, 8) = Adodc1.Recordset.Fields(7)
                                                With xlapp.Cells(i, 8).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                
                                                xlapp.Cells(i, 9) = Adodc1.Recordset.Fields(8)
                                                With xlapp.Cells(i, 9).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                xlapp.Cells(i, 10) = Adodc1.Recordset.Fields(9)
                                                With xlapp.Cells(i, 10).Borders
                                                        .LineStyle = 1
                                                        .Weight = 2
                                                End With
                                                
                                                Adodc1.Recordset.MoveNext
                                                i = i + 1
                       Loop
                                                        
                    '   With Sheets("sheet1").Range(Cells(4, 1), Cells(3 + n, 10)).Borders
                            ' .LineStyle = 1
                            ' .Weight = 2
                     '  End With
以上修改暂时都通过了。各种测试均正常。最终原因还是没找到。
2018-05-19 16:58
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
收藏
得分:20 
问题出在这条语句
With xlapp.Range(Cells(4, 1), Cells(3 + n, 10)).Borders
改为如下即可
With xlapp.Range(xlsheet.Cells(4, 1), xlsheet.Cells(3 + n, 10)).Borders

cells是代表单元格,一个excel应用程序(Application)有多个工作簿(workbook),每个工作簿有多个表格(worksheet),每个表格有各自的单元格(cells),在用到表格时必须指定是哪个工作簿的,在用到单元格时必须指定是哪个表格的。

修改为xlsheet.Range就可以唯一确定cell。
cell没有xlsheet,第一次采用你创建的第一个app,此时调用第一个app的cell,可以成功
cell没有xlsheet,第二次采用你创建的第二个app,此时调用第一个app的cell,因此报错【可能是app内部没有完全销毁】




[此贴子已经被作者于2018-5-20 11:58编辑过]

2018-05-20 11:42
zhulei666
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2018-5-19
收藏
得分:0 
多谢楼主,测试通过!
我曾实验过  With xlapp.xlsheet.Range(Cells(4, 1), Cells(3 + n, 10)).Borders
结果系统提示 无此语法,武艺不精,没想到楼主的更改。
但是心问题出来了,这些赋值语句,没有xlsheet为啥每次都能执行成功呢?
                                                xlapp.Cells(i, 1) = Adodc1.Recordset.Fields(0)
                                                xlapp.Cells(i, 2) = Adodc1.Recordset.Fields(1)
                                                xlapp.Cells(i, 3) = Adodc1.Recordset.Fields(2)
                                                xlapp.Cells(i, 4) = Adodc1.Recordset.Fields(3)
    每次总是在给单元格画边框时出问题。
我把画边框提到赋值语句前面,也是提示462的错误。
能帮我研究一下。叩谢!                                
2018-05-20 20:35
zhulei666
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2018-5-19
收藏
得分:0 
跟您探讨:
1、为了确保cell的唯一,我给这个打印专门设置了一个Excel,里面只有一个sheet,还是出现这样的问题。
   理论上讲,只有一个表,一个sheet,可以保证cell的唯一了。
2、APP有什么办法彻底干掉吗?调用同一个APP,也视作两个APP?
3、cell没有xlsheet,第二次采用你创建的第二个app,此时调用第一个app的cell,因此报错【可能是app内部没有完全销毁】 这句话,可能没
完全解释原因。第二次调用时,赋值语句执行顺利(数据正确),我觉得调用的是第二个APP的cell。
2018-05-20 20:54
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
收藏
得分:0 
探讨:
1、为了确保cell的唯一,我给这个打印专门设置了一个Excel,里面只有一个sheet,还是出现这样的问题。
  调用时直接书写cell,他会有一个默认app或者sheeet
  书写为xlapp.cell,xlsheet.cell一般不会出错。
2、APP有什么办法彻底干掉吗?调用同一个APP,也视作两个APP?
  创建程序或者文件时,系统都会随机分配内存作为程序或者文件的存储。
  Set MyObject = Nothing这是取消myobject与这块存储的关系,并没有销毁存储的内容。
  【关键的问题点还在于默认的cell调用的是哪个地址的数据】
3、cell没有xlsheet,第二次采用你创建的第二个app,此时调用第一个app的cell,因此报错【可能是app内部没有完全销毁】 这句话,可能没
完全解释原因。第二次调用时,赋值语句执行顺利(数据正确),我觉得调用的是第二个APP的cell。
  我又重新测试了一下
   单独cell没有指定的情况下,赋值语句没问题【cells,xlapp.cells,sheet.cells】
   range的cell没有指定的情况下,出错,如果加了xlapp.cell或者sheet1.cell不会报错
 
 总结:问题原因就是cell没有限定,书写完整语句可以避免此问题。
  



[此贴子已经被作者于2018-5-21 08:49编辑过]

2018-05-21 08:24
zhulei666
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2018-5-19
收藏
得分:0 
多谢楼主费心!
1,XLAPP.CELL形式与RANGE连用,
必须像楼主第一次写的那样才行With
xlapp.Range(xlsheet.Cells(4, 1), xlsheet.Cells(3 + n, 10)).Borders
。其他方式我试过,基本报错。
例如xlapp.XLSHEET.Range(Cells(4, 1), Cells(3 + n, 10)).Borders的形式
再次感谢!
2018-05-21 09:16
快速回复:远程服务器不存在或不能使用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029007 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved