|
-
Sep 28th, 2009, 01:33 AM
#1
Thread Starter
Junior Member
[RESOLVED] Using Excel 2003 object to open *.xlsx file in VB6
Hi all,
I got an issue where using [VB6 + Excel 2003 + Office 2007 Compatibility Pack] to open *.xlsx (Excel 2007) file returns me the following error:-
This file is not in a recognizable format.
• If you know the file is from another program which is incompatible with Microsoft Office Excel, click Cancel, then open this file in its original application. If you want to open the file later in Microsoft Office Excel, save it in a format that is compatible, such as text format.
• If you suspect the file is damaged, click Help for more information about solving the problem.
• If you still want to see what text is contained in the file, click OK. Then click Finish in the Text Import Wizard.
Here is the sample code to open the file:-
Code:
Excel.Workbooks.open "<xlsx file>"
However the same method is applicable for Word 2003 to open *.docx file.
Another thing is the issue is only happen when open via VB6.
It has no problem to open normally by user (double click .xlsx file and it will convert accordingly if compatibility pack installed)
Is it a limitation or for security reason the feature is blocked?
Appreciate much if get feedbacks...
-
Sep 28th, 2009, 05:34 AM
#2
Re: Using Excel 2003 object to open *.xlsx file in VB6
try recording macro of opening file from excel
it may require insert method
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 28th, 2009, 08:00 AM
#3
Re: Using Excel 2003 object to open *.xlsx file in VB6
Good suggestion on the macro recording.
Programmatically opening the xlsx file may be missing some compatibility step or process that the compatibility pack is doing. I would think there is a conversion method invoked before its actually opened.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 29th, 2009, 03:06 AM
#4
Thread Starter
Junior Member
Re: Using Excel 2003 object to open *.xlsx file in VB6
Guys, i found an alternative solution to this issue already.
Code:
Call Shell("C:\Program Files\Microsoft Office\Office12\Moc.exe " & "C:\Book1.xlsx")
*Moc.exe is Open XML format converter provided after Office 2007 Compatibility Pack installed.
The Office 2007 Compatibility Pack will do the conversion job 1st before proceed to open the converted file (in temp folder). If the xlsx file is being open via [Excel 2003 > File > Open], it will be the same issue as via programmatically.
Thanks a lot guys for the suggestions which helped to guide me to the right way
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|