Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA in windows seven 64 bit and word Vba 2010 in 32 bit version, couldnt access excel through word

    My client machine is windows seven 64 bit version. we have Ms office is 32 bit version my machine. I m trying to access the excel application from word vba. I have added reference Microsoft excel 14.0 object in word document. but the code is not not working.


    code as follows:
    Code:
    Dim xlApp As Object
    Dim xlBook As Object
    Set xlApp = GetObject(, "Excel.Application")
      If xlApp Is Nothing Then
        Set xlApp = CreateObject("Excel.Application")
        MsgBox "Cannot open Excel."
      End If
    Exit Sub


    Can anyone give me the solution for this ??



    But the above code is working fine in 32 bit windows seven and 32 bit MS office 2010..


    Thanks in advance

    Regards,
    udhaya.
    Last edited by RetiredGeek; 2013-09-13 at 11:38. Reason: Added code tags

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    udhaya

    Welcome to the Lounge as a new poster!

    Give this a try.

    You can set up some conditional compiliation so that you can try both early and late binding. Early binding is good for code development where you want access to the auto complete features of the VBA. Late Binding is good for deployment since you don't have to worry if the users have references set.

    Note: This is air code adapted from code I use to call Outlook from Access so it may need some minor changes. I did look up the xlWorkbook value in the Excel Object browser so I know that is correct.

    Code:
    #Const LateBinding = 0   'Early binding = 0 Late Binding = 1 Change for testing.
    
    Sub Test()
    #If LateBinding = 0 Then  'Early Binding
      Dim xlApp as Excel.Application
      Dim xlBook as Excel.Workbook
    #Else
      Dim xlApp As Object
      Dim xlBook As Object
    #End If
    
        Set xlApp = CreateObject("Excel.Application")
        If xlApp Is Nothing Then 
          MsgBox "Cannot open Excel."
          Exit Sub
       End If
    
    #IF LateBinding = 0 Then
        Set xlBook = xlApp.CreateItem(xlWorkbook) 'xlWorkbook = 1
    #Else
        Set xlBook = xlApp.CreateItem(1)
    #End If
    
    End Sub
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    udhaya,

    The above code is deeply flawed

    See this post for the correct TESTED code to get to Excel from another Office Application.

    Sorry about that but when I answered you I was short on time. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #4
    New Lounger
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Geek!!!!! It worked !

  5. #5
    New Lounger
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Geek,

    Can u give suggestion/solution to the below problem?

    I want to remove the broken reference from word documents. I can able to find out number of reference in document including broken reference. but when i try to remove the reference/ get the broken reference name with the following code, I got run time error. I tried with following codes but nothing worked out for me.

    Code as follows:

    Dim vbProj As VBProject
    Dim chkRef As Reference
    Dim i as Integer

    I= VBE.ActiveVBProject.references.Count
    Msgbox i
    Set vbProj = ActiveDocument.VBProject

    For Each chkRef In vbProj.References
    Msgbox chkref.Name
    If chkRef.IsBroken Then
    vbProj.References.Remove chkRef

    End If

    Next

    End Sub


    Sub A()

    Dim Z as object
    For Each z In Application.VBE.ActiveVBProject.references

    If z.IsBroken = true Then
    Set Z = Application.VBE.ActiveVBProject.references.item("P PC")
    Application.VBE.ActiveVBProject.references.Remove z

    End If

    Next

    End sub

    Whenever the code reaches the broken reference , I got the runtime error (Name, FullPath doent work ). Machine is window s7 64 bit.. word is 32 bit version 2010.

    Thanks in advance..

    Regards,
    udhaya. Edit Post Reply Reply With Quote Thanks .

Posting Permissions

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