权限被拒绝使用Excel 12.0 Library& VB6 [英] Permission Denied opening an Excel File using Excel 12.0 Library & VB6

查看:283
本文介绍了权限被拒绝使用Excel 12.0 Library& VB6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前我已经在VB6应用程序中使用了Excel,并且从未遇到过这样一个奇怪的问题,试图很容易地完成某些工作。



我正在尝试打开一个excel(xls或xlsx)文件并读取值,你可能会看到。



当我尝试打开文件时,我收到错误70权限被拒绝)错误。奇怪的是,没有其他的excel开放实例(在任务管理器应用程序或进程中)。没有人试图访问该文件。我可以在没有警告的情况下打开excel文件,我也可以使用基本的Open File for Input as#1语法来打开/读取/关闭VB6中的文件,没有错误。我可以使用Kill()删除该文件,因此它不能是目录权限问题 - 请帮助 - 我失去了!!!

  Dim xlApp As New Excel.Application 

Dim xlWBook As Excel.Workbook

'错误发生在这里
设置xlWBook = xlApp.Workbooks.Open (文件)

Dim xlSheet作为Excel.Worksheet
设置xlSheet = xlWBook.Sheets.Item(1)

Dim y As Integer
对于y = 1 To 99999
如果Len(xlSheet.Cells(y,1))> 0然后
发送xlSheet.Cells(y,1)& - & xlSheet.Cells(y,2)& <峰; br> 中
结束如果
下一个

设置xlWBook =没有
设置xlApp =没有

-Jay

解决方案

  Dim xlApp As New Excel.Application 
Dim xlWBook As Excel.Workbook
'出现错误
设置xlWBook = xlApp.Workbooks.Open(文件)

没有定义哪个文件是。即。

  File =C:\myDocuments\myexcel.xlsx。 '因为文件字符串是空的。 


I have used Excel in my VB6 apps many times before, and have never run into such a weird problem trying to accomplish something very easy..

I am trying to open an excel (xls or xlsx) file and read through values, as you can probably see.

When I try to open the file, I get an error 70 (permission denied) error. The odd thing is that there is no other instance of excel open (in task manager apps or processes). No one else is trying to access the file whatsoever. I can open the file in excel with no warning, and I can also open/read/close the file in VB6 with the basic "Open File for Input as #1" syntax without error. I can delete the file using Kill() so it can't be a directory permissions issue - Please help - I am at a loss!!!

  Dim xlApp As New Excel.Application

  Dim xlWBook As Excel.Workbook

  'Error Occurs Here
  Set xlWBook = xlApp.Workbooks.Open(File)

  Dim xlSheet As Excel.Worksheet
  Set xlSheet = xlWBook.Sheets.Item(1)

  Dim y As Integer
  For y = 1 To 99999
    If Len(xlSheet.Cells(y, 1)) > 0 Then
      Send xlSheet.Cells(y, 1) & " - " & xlSheet.Cells(y, 2) & "<br>"
    End If
  Next

  Set xlWBook = Nothing
  Set xlApp = Nothing

-Jay

解决方案

Dim xlApp As New Excel.Application    
Dim xlWBook As Excel.Workbook    
'Error Occurs Here   
Set xlWBook = xlApp.Workbooks.Open(File) 

There is no defined which File is. ie.

File="C:\myDocuments\myexcel.xlsx". 'Because File string is empty.

这篇关于权限被拒绝使用Excel 12.0 Library&amp; VB6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆