Visual Basic 6 - 导出到Excel 2010/2013不起作用

问题描述:

嗨朋友们,



我遇到了这个问题,需要你的帮助。



我们有一个VB6应用程序读取Excel文件(基本上像模板)并将数据写入特定单元格,最后将其导出到xls。



问题是excel工作表2013版不开放。当我打开文件时,一切都是空白的。但文件大小表明数据已写入其中。此外,该文档在Google文档中打开,但不在办公室2013版本。



下面请找到我的代码。 (实际代码太长,因此无法在此处粘贴)。



Hi Friends,

I am stuck with this issue and need your help.

We have one VB6 application that reads an Excel file (basically like a template) and writes data into specific cells finally exports it to a xls.

The problem is that the excel sheet is not opening in office 2013 version. When I open the file, everything is blank. But the file size indicates that data got written into it. Moreover , the document is opening in Google docs but not in office 2013 version.

Below please find my code for it. (actual code is too long therefor can't paste it here).

Set xlApp = Excel.Application
   Set xlBook = GetObject("file.xls")
   Set xlSheet = xlBook.Worksheets(1)
   Set xlsheet2 = xlBook.Worksheets(2)

 --logic

   xlBook.SaveAs output.xls 





(请注意:我正在使用Windows 7 - 64位系统。我正在使用所有必需的DLL)



任何帮助将不胜感激。非常感谢提前!!



(Please note: I am using Windows 7 - 64 bit system. I am using all required DLL)

Any help would be appreciated. Thanks a lot in advance!!

您没有提供有关您的问题的足够信息,特别是有关该行为的原因。您也没有提供代码。好吧,我们只能猜测...



首先,我建议阅读在自动化中使用早期绑定和后期绑定 [ ^ ],早期和晚期绑定(Visual Basic) [ ^ ]。



一旦使用:

You did not provide enough information about your issue, especially about the reason of that behaviour. You did not provide your code too. Well, we can only guess...

First of all, i'd suggest to read about Using early binding and late binding in Automation[^], Early and Late Binding (Visual Basic)[^].

Once you are using:
Set xlApp = Excel.Application 'early binding



然后


and then

Set xlBook = GetObject("file.xls") 'late binding



您需要决定要使用哪种绑定方法。



其次,您需要使用Excel的对象和方法:


You need to decide which binding method do you want to use.

Secondly, you need to use Excel's object and methods:

Dim xlApp As Object
Dim xlWbk AS Object
Dim xlWsh AS Object

Set xlApp = CreateObject("Excel.Application")
Set xlWbk = xlApp.Workbooks.Open("FullFileName.xls")
Set xlWsh = xlWbk.Worksheets("SheetName")

With xlWsh
    .Range("A1") = "Test"
    .Range("C3") = 3
End With

'...

'finally, clean up:
xlWsh = Nothing
xlWbk.Close SaveChanges:=True
xlWbk = Nothing
xlApp.Quit
xlApp = Nothing







第三,MS Office 2010/2013存在已知问题:

Office 2013中的兼容性问题 [ ^ ]

基于VB6的加载项可能无法在Office 2013中运行 [ ^ ]



最后,请参考:

Visual Basic 6开发人员基本培训 [ ^ ]



顺便说一句:我想说:当VB.NET更强大,更高效等时,谁想要使用VB6?




Thirdly, there are known issues with MS Office 2010/2013:
Compatibility issues in Office 2013[^]
VB6 based add-ins may fail to work in Office 2013[^]

Finally, please refer this:
Essential Training for Visual Basic 6 Developers[^]

By The Way: I'd like to say: who wants to use VB6, when VB.NET is more powerful, efficient, etc.?