Click here to Skip to main content
16,021,288 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
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).

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

 --logic

   xlBook.SaveAs output.xls 


(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!!
Posted
Comments
Maciej Los 11-Apr-14 15:54pm    
Please, provide more details about the way you declare variables...

1 solution

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:
VB
Set xlApp = Excel.Application 'early binding

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

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

Secondly, you need to use Excel's object and methods:
VB
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



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.?
 
Share this answer
 
Comments
CHill60 12-Apr-14 5:34am    
5'd. I especially like the link to Essential Training - new to me.
I also found "The Book of Visual Basic 2005 - .NET Insight for Classic VB Developers" quite good (Matthew MacDonald No Starch Press ISBN:1-59327-074-7)
Maciej Los 12-Apr-14 6:15am    
Thank you, Chill ;)
Joy1979 25-Apr-14 14:11pm    
Hello Maciej Los and Chill60. Sorry for my late response.
Thank you Maciej Los, I've applied the logic mentioned in your answer. Working as expected!! Grt work.
Maciej Los 28-Apr-14 15:42pm    
You're welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900