Results 1 to 8 of 8

Thread: explain this code?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    explain this code?

    can some one please help me by explaining this code to me? i understand some of it, i just need to know what it does, line by line if possible. thanx for any help
    VB Code:
    1. Dim objWord As New Word.Application
    2. objWord.Documents.Add
    3. ActiveDocument.ToggleFormsDesign
    4.     objWord.Selection.InlineShapes.AddOLEControl ClassType:="Forms.CheckBox.1"
    5. ActiveDocument.ToggleFormsDesign
    6. objWord.Visible = True

  2. #2
    Lively Member
    Join Date
    Mar 2004
    Location
    UK
    Posts
    109

    Re: explain this code?

    1: Create a connection to Word

    2: Add a new document

    3: Add a checkbox to the current doc

    4: Go back to forms design mode

    5: Make it visible

    Nick
    UK Software Development http://www.all4yourpc.co.uk

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    ok thanx alot.
    VB Code:
    1. ActiveDocument.ToggleFormsDesign
    2.     objWord.Selection.InlineShapes.AddOLEControl ClassType:="Forms.CheckBox.1"
    is this all one line?
    also the
    VB Code:
    1. ClassType:="Forms.CheckBox.1"
    could one use this for check boxes that are in a VB6 app, just by changing the name?

  4. #4
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    Are you sure that's Visual Basic codes?
    I mean it looked that way at a quick glance...but it was this that threw me off to thinking otherwise....

    ClassType:="Forms.CheckBox.1"
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    yeah i think that it is VB code, someone gave me this off of this forum, i was asking if there was a way to put check boxes into MSWord from a VB app.

  6. #6
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    It absolutely is VB code....remember that VB is fully supported by COM, and as such, you are able to access a wide variety of components. In the example provided in this thread, the component accessed is an object of type Word.Application (application object)....this is what OLE Automation is all about....the ability to create instances of objects external to your application....this sort of began when companies like Microsoft and Lotus looked for ways to allow users to embed spreadsheets in their word documents, and other operations like that. But from the programming point of view, this also means that we can access these components and do stuff with them according to our needs (like add checkboxes to a word document).

    Dubya, someone at some point in this forum made an excellent suggestion: when you record a macro in Word, and then save the macro, go back and open the dialog to run it. But do not run it, instead, click on 'Edit'. The VB editor will open and you will see the code that was generated. This code is supported by the objects that word supports (these objects have properties and methods)....so if you instantiate the same type of objects in VB, you will have the same properties and methods available to you. Hope that is not too confusing. cheers
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    that a good idea about the macro. do u know it is possible to put the check marks at a specific place in the Word document, such as a bookmark?

  8. #8
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    well...why don't you open Word, start recording a macro, then add a bookmark (please don't ask me how to add a bookmark in Word!! ). Stop the Macro and then go to edit it to see the code. This really does work most of the time. In fact, the only times you won't get the code you need right from the macro editor, is when you need to apply some loops or conditions....but I am confident that an able and ambitious person such as yourself will extrapolate successfully!!
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

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