Here is a little test workbook. Open the visual basic editor and double click on the user form. Run the form, select a word doc file and press the GetWord button. The text from the Word Doc will go into the large multiline textbox.
Have Fun...
Don't quite get it, I thought that the Document object would be what I wanted to reference, not the Application.
I think this is something that you just learn as time goes on.
I was a VB6 programmer for over 13 years when I got tossed into the middle of a bunch of VBA apps about a year ago.
I still get tripped up over this particular aspect of using VBA, but it has nailed me so many times, that I now just automatically try the "other" thing, if the first one doesn't work.
Looks like my whole problem was that when I was trying to use Selection I should have been using it with WordApp not WordDoc!
Don't quite get it, I thought that the Document object would be what I wanted to reference, not the Application.
In any case it works great! Much obliged!
thegeeber
Actually you mean just the opposite. Selection is part of the Application object not the Document object. You were using the Document object when you should have been using the Application object.
I think this is something that you just learn as time goes on.
I was a VB6 programmer for over 13 years when I got tossed into the middle of a bunch of VBA apps about a year ago.
I still get tripped up over this particular aspect of using VBA, but it has nailed me so many times, that I now just automatically try the "other" thing, if the first one doesn't work.
VBA is basically the same as VB6. The thing that seems to hang most people up is the differences between the applications that implement VBA. Each application has it's own set of objects. These objects from the Application object on down are part of the application in which VBA is implemented.
Because of this they have similar but different properties and methods; which can be very confusing when you switch between applications, like Excel, Word, or MS Access.
You must always keep in mind that the objects are different. When you develop in VBA you should always define your object variables as the type of object you are accessing. Example of this is MS Words document object. If you declare your variable as type Object then VBA cannot help you with the available properties and methods; but if you define it as a Word.Document type, then VBA can help you with the properties and methods.
Intellisence can give you a list when you access the objects while you are coding, plus you can select the specific property or method and hit F1 to get detailed help on it.
Once you have debugged your application then you can switch the Object variable definitions to type Object. Doing this allows you to develope code that is version independent. An app written in Version 9 will be able to run in version 10. This is mostly important when you access external applications like when Excel accesses Word objects.
Durning development of your Excel app you set the Word 9 object references; but once the app is debugged you should remove the word 9 objects references and change the variable definitions to type Object. This prevents object reference version errors. If you have the Word 9 object references set and your user only has version 10 or 11 you will get errors.