Results 1 to 2 of 2

Thread: Help on excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    Help on excel

    Hi,

    I have written a VBA procudure in excel using Microsoft office 10.0 Object library. But I am not able to run this on other comps. since the Object library is different (11.0). I guess this is the reason for the procedure to not work. Can someone please help troubleshoot this problem. Is these a way to make this procedure compatiable across all computers irrespective of version differences?????

    Thanks in advance
    Siddharth

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help on excel

    You need to use Late Binding instead of Early Binding. Late binding does not require a reference to Excel at all allowing the use of different versions. You do need to be careful to only use properties, methods, and functions that are supported by the versions of Excel you need to support.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim oApp as Object
    5.     Dim oWB as Object
    6.     Set oApp = CreateObject("Excel.Application")
    7.     Select Case oApp.Version
    8.         Case "10.0", "11.0", "12.0"
    9.             'Valid supported version or ???
    10.         Case Else
    11.             MsgBox "Excel Version not supported!"
    12.             'Exit your application or disable features.
    13.     End Select
    14.     Set oWB = oApp.Workbooks.Open("C:\BVook1.xls")
    15.     oWB.Sheets("Sheet1").Cells(1, 1) = "Test"
    16.     oWB.Save
    17.     oWB.Close
    18.     Set oWB = Nothing
    19.     oApp.Quit
    20.     Set oApp = Nothing
    21.  
    22. End Sub
    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 PostsVS.NET on Vista Multiple .NET Framework Versions 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 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width