3

I'm writing some code which manipulates other office applications ( office ). When I write my code I would like to have the VBE help me with the properties and functions just as it does for those linked to excel.

How is this done? E.g I would like the VBE to give me "bookmarks" as an drop-down alternative when i enter word_doc and add a dot after. Just like it does after I have the word_doc set to open an excel file.

word_doc --> Set word_doc = word_app.documents.Open("C:\Users\sjan\Desktop\MailingLetter.docx")

Community
  • 1
  • 1
uncool
  • 2,613
  • 7
  • 26
  • 55

2 Answers2

5

You have to Early Bind the Word Application to get Word hints to work on your Excel VBA window. In the Excel VBE, Go to Tools|References and scroll down to Microsoft Word xx.0 Object Library and click the checkbox. Then, try this code.

Sub testword()
    ' Declare the object as a early-bound object
    Dim oWord As Word.Application
    Set oWord = CreateObject("Word.Application")

    With oWord
        .Visible = True
        Stop
    '~~~>Type a dot above this line to see all the Word choices
    End With
End Sub
L42
  • 19,427
  • 11
  • 44
  • 68
tbur
  • 2,384
  • 1
  • 13
  • 12
  • @L42 No problem with your edits. And I can't for the life of me get `End Sub` to be in the code section. Ever. No idea what I'm doing wrong there. :( – tbur Aug 22 '14 at 02:56
  • 1
    You can do it manually by spacing it out. :) You can also use simple HTML tags here. (e.g.
    (for line breaks),
     (for pre-formatted text), etc.). Also, you can see preview of what you post, so you can see if it looks good or not. And if somebody edit's your post, it's ok. It just means that your answer is useful and deserves a more readable format. Anyways, you can always roll it back if you think it radically change your answer.
    – L42 Aug 22 '14 at 03:12
  • I get an issue, I have now the object library added and selected in my reference library but still it doesn't show up. I have for another set of code now ( see below ) and I've added the Microsoft HTML Object Library and Microsoft Internet Controls but still nothing shows up after ie_app + dot. Code: Private Sub get_ticker() Dim ie_app As Object Dim ie_dod As htmldocument Set ie_app = CreateObject("internetExplorer.application") ie_app. End Sub – uncool Aug 22 '14 at 06:58
  • I now notized why the hints don't show up even thought the object libraries were added in the references. Declaring ie_app ' internetexplorer object as Object makes the internet explorer library unavilable but when delcaring ie_app as internetexplorer makes it all work again. Why is this the case? – uncool Aug 22 '14 at 07:30
  • This might help. [What is early and late binding?](http://stackoverflow.com/questions/10580/what-is-early-and-late-binding) – RubberDuck Aug 22 '14 at 11:15
3

In addition to early binding, the intellisense often breaks if the code won't compile. On the menu bar, click Debug >> Compile to show any errors that could be preventing Intellisense from working.

L42
  • 19,427
  • 11
  • 44
  • 68
RubberDuck
  • 11,933
  • 4
  • 50
  • 95