vba 权限被拒绝使用 Excel 12.0 库和 VB6 打开 Excel 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/425092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Permission Denied opening an Excel File using Excel 12.0 Library & VB6
提问by HemiJay
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..
我以前在我的 VB6 应用程序中多次使用 Excel,并且从未遇到过如此奇怪的问题,试图完成一些非常简单的事情。
I am trying to open an excel (xls or xlsx) file and read through values, as you can probably see.
我正在尝试打开一个 excel(xls 或 xlsx)文件并读取值,您可能会看到。
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!!!
当我尝试打开文件时,出现错误 70(权限被拒绝)错误。奇怪的是,没有其他 excel open 实例(在任务管理器应用程序或进程中)。没有其他人试图访问该文件。我可以在没有警告的情况下在 excel 中打开文件,我也可以在 VB6 中使用基本的“打开文件作为 #1”语法打开/读取/关闭文件而不会出错。我可以使用 Kill() 删除文件,所以它不会是目录权限问题 - 请帮忙 - 我不知所措!!!
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
-杰
回答by Dirk Vollmar
Can you open a newly created empty spreadsheet document?
你能打开一个新创建的空电子表格文档吗?
If that doesn't work it might be that your Excel installation needs to be re-registered. Open a command prompt and navigate to the folder where Excel is installed, typically something like
如果这不起作用,则可能是您的 Excel 安装需要重新注册。打开命令提示符并导航到安装 Excel 的文件夹,通常类似于
cd "C:\Program Files\Microsoft Office\Office12"
and then start Excel with the option /regserver
然后使用选项 /regserver 启动 Excel
excel.exe /regserver
If this doesn't help you could go to Control Panel -> Add or Remove Programs and start a repair of Microsoft Office.
如果这没有帮助,您可以转到控制面板 -> 添加或删除程序并开始修复 Microsoft Office。
Another thing to check would be whether there are any add-ins loaded. If so, try to disable them one by one and see whether the problem disappears.
要检查的另一件事是是否加载了任何加载项。如果是这样,请尝试将它们一一禁用,看看问题是否消失。
If the problem still persists you might want to check for any Office updates available.
如果问题仍然存在,您可能需要检查是否有任何可用的 Office 更新。
I don't know if all this is related to your problem, it's rather standard troubleshooting techniques of Office applications...
我不知道这一切是否与您的问题有关,这是 Office 应用程序的标准故障排除技术...
UPDATE: Maybe troubleshooting with Procmon will reveal where the problem lies (see http://support.microsoft.com/kb/286198).
更新:也许使用 Procmon 进行故障排除会揭示问题所在(请参阅http://support.microsoft.com/kb/286198)。
回答by Andy
Have you checked your DCOM config.
你有没有检查过你的 DCOM 配置。
Had a similar issue today, where a web service that was trying to create the Excel.Application was receiving a access denied.
今天有一个类似的问题,一个试图创建 Excel.Application 的 Web 服务接收到访问被拒绝。
In my instance I had to add the internet guest account to have access permissions to the component.
在我的实例中,我必须添加 Internet 访客帐户才能访问该组件。
You can get to the DCOM config from Start -> Run
您可以从“开始”->“运行”进入 DCOM 配置
Type DCOMCNFG - hit enter
输入 DCOMCNFG - 按回车键
Then browse to Component Services/Computers/My Computer/DCOM Config/Microsoft Excel Application
然后浏览到组件服务/计算机/我的电脑/DCOM 配置/Microsoft Excel 应用程序
Right click, properties...
右键,属性...
The settings are under the Security tab.
这些设置位于“安全”选项卡下。
回答by Excel expert
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.
没有定义哪个文件是。IE。
File="C:\myDocuments\myexcel.xlsx". 'Because File string is empty.
回答by Marcand
You seem to create a new Excel instance without explicitly closing it (i.e. xlApp.Close before setting it to Nothing). That may be the cause of you problems.
您似乎在没有明确关闭它的情况下创建了一个新的 Excel 实例(即在将其设置为 Nothing 之前 xlApp.Close)。这可能是您出现问题的原因。
Some times stuff goes haywire if there is some loose instances of Office Apps running about when calling them from VBA. If you have some Excel.exe running in the task manager but you can't see the application on the screen or task bar then kill them and retry.
有时,如果在从 VBA 调用 Office 应用程序时运行一些松散的 Office 应用程序实例,事情就会变得混乱。如果您在任务管理器中运行了一些 Excel.exe,但在屏幕或任务栏上看不到该应用程序,请杀死它们并重试。
回答by Raminder
Maybe it's not the file that the permission is denied to.
也许这不是权限被拒绝的文件。
回答by jac
Just a thought, have you looked at the Windows event log to see if you can find more information there?
只是想一想,您是否查看了 Windows 事件日志以查看是否可以在其中找到更多信息?
回答by afewcc
This could happen when there is a problem in the excel file, a consistency problem. The file is kind of corrupted.
这可能发生在 excel 文件中存在问题时,即一致性问题。文件有点损坏。
For example, there are 2 objects on the sheet with the same name. The point is, I cannot tell how it's been possible that your file has been saved with this kind of "problem" but when Excel try to open it, it throws this kind of error.
例如,工作表上有 2 个具有相同名称的对象。关键是,我不知道您的文件是如何以这种“问题”保存的,但是当 Excel 尝试打开它时,它会引发这种错误。