Share via

Are OLE objects supported for Visual Basic in Excel?

Anonymous
2012-01-04T09:56:19+00:00

Hi everybody!

I'm working with visual basic for Excel Mac, version 2011. I have problems with code created in Excel 2003 for Windows when there are OLE objects. I don't know if OLE objects are supported by Visual Basic for Mac. Anyone know anything?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-01-04T13:20:49+00:00

Mac Office VBA provides some OLE support  - you may need to make a reference to the OLE Automation library (Tools/References in the VBE).

Note one significant difference is that you can't use CreateObject to create a second instance of a running application - MacOS only allows one instance. So you should first try GetObject(), and only if that doesn't work , try CreateObject(), e.g.:

Dim oWordApp As Object

   On Error Resume Next

   Set oWordApp = GetObject(, "Word.Application")

   On Error GoTo 0

   If oWordApp Is Nothing Then _

      Set oWordApp = CreateObject("Word.Application")

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-02-09T20:51:00+00:00

    J.E.- Question I'm trying to utilize this logic. I wrote something that works in Excel for PC but not for the Mac. The last two lines are where the issue is. Get object doesnt seem to work but create object does. any ideas why the mac gives me an error on the last line. Trying to set wdDoc = WdApp.Douments(1)?


    Sub GenerateWordDoc()

    Dim wdApp As Object

    Dim wdDoc As Object

    Dim wb As Excel.Workbook

    Dim xlName As Excel.Name

    'Define Workbook

    Set wb = ActiveWorkbook

    On Error GoTo ErrorHandler

    'Open Template in word

    wd = Sheets("Hidden Data").Shapes("Object 1").OLEFormat.Verb(Verb:=xlVerbOpen)

    Set wdApp = GetObject(, "Word.Application")

    Set wdDoc = wdApp.Documents(1)

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-01-05T09:16:42+00:00

    Thanks for the explanations

    FJLM

    Was this answer helpful?

    0 comments No comments