防止文件现在可用弹出式Excel

防止文件现在可用弹出式Excel

本文介绍了防止文件现在可用弹出式Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个问题,我已经工作了几个小时了.

I have a problem here that I've been working on for hours.

我正在导入一个Excel文件,并使用以下代码来做到这一点:

I'm importing an Excel file, and I use this code to do it:

   Dim objExcel As Excel.Application
        Dim objWorkBook As Excel.Workbook
        Dim totalWorkSheets As Excel.Worksheet
        Dim ExcelSheetName As String = ""

        objExcel = CreateObject("Excel.Application")
        objWorkBook = objExcel.Workbooks.Open(excelfile, Notify:=False)
        objExcel.DisplayAlerts = False
        Dim exConS As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & excelfile & ";Extended Properties=Excel 8.0;"


        For Each totalWorkSheets In objWorkBook.Worksheets
            ExcelSheetName += totalWorkSheets.Name
            Dim exCon As New OleDbConnection(exConS)
            Dim dsExcel As New DataSet()
            exCon.Open()
            Dim sExcel As String = "SELECT * FROM [" & totalWorkSheets.Name & "$]"
            Dim daExcel As New OleDbDataAdapter(sExcel, exCon)
            daExcel.Fill(dsExcel)
            exCon.Close()
         Next totalWorkSheets

 objWorkBook.Close()
objExcel.Quit()
Dim ggProcess As New Process
ggProcess = Process.Start("EXCEL.EXE")
ggProcess.Kill()

问题是当我运行代码时,以下对话框一直出现:

The problem is that the following dialog box keeps appearing when I run the code:

如何防止此弹出对话框出现?

How can I prevent this pop-up dialog box from appearing?

推荐答案

根据超级用户的建议,可以简单地进行更改

As poweruser has suggested can simply change

objWorkBook = objExcel.Workbooks.Open(excelfile, Notify:=False)

objWorkBook = objExcel.Workbooks.Open(excelfile, Notify:=False, Readonly:=True)

好吧,因为那没有用,所以我对代码进行了更详细的研究,认为您的问题是因为您正在打开excel文件,然后为其创建外部连接.不必打开该文件即可为它创建OLEDB连接.

Ok since that didn't work I've taken a more detailed look at the code and think your issue is because you are opening the excel file, then creating an external connection to it. The file does not have to be open in order create an OLEDB connection to it.

看来您不预先知道选项卡的名称,所以您需要打开文件来获取选项卡的名称吗?

It appears that you don't know the tab names in advance so you need to open the file to get the tab names?

如果是这样,我将创建一种打开文件的方法,以获取选项卡名称并返回选项卡名称的数组,然后您可以在上面的代码中对其进行迭代,然后关闭文件.

If so I would create a method to open the file get the tab names and return an array of the tab names which you can then iterate through in your code above, then close the file.

这篇关于防止文件现在可用弹出式Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:15