Results 1 to 4 of 4

Thread: [RESOLVED] Using Excel 2003 object to open *.xlsx file in VB6

  1. #1
    Junior Member
    Join Date
    Dec 05
    Posts
    19

    Resolved [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...

  2. #2
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,520

    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

  3. #3
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 01
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,465

    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 (VBA, VB 6, VB.NET, C#)
    Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007

  4. #4
    Junior Member
    Join Date
    Dec 05
    Posts
    19

    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
  •