Results 1 to 8 of 8

Thread: [Excel]Passing variable between macro of excel and word

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    [Excel]Passing variable between macro of excel and word

    i have create macro for both excel and word, so there is 2 macro will be running Simultaneously, my problem is these 2 macro must be able to passing value to each other, is any method to do that?

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [Excel]Passing variable between macro of excel and word

    The easiest way would be to store the value in a file and read it out of the file.

    But why don't you use a single macro for both projects, if it is started by Excel, word could be opened by the macro, that way you would have direct access to the values!!
    If you give more detail, we could help!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: [Excel]Passing variable between macro of excel and word

    thanks...is this the only solution?

    the project i going to do is like this...

    The macro is start from excel to generate a customized table in a sheet, but in word document will have a another macro(activate by a command button in word document) to call out something like reference table(generated by user form), if the user click on a cell in this reference table, a repective value will be copy to this word document, this is easy for user to create a word document, and all the value from this reference table is take from excel workbook.

    In my case, is single macro able to handle all the task?

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [Excel]Passing variable between macro of excel and word

    Quote Originally Posted by lighthouse
    The macro is start from excel to generate a customized table in a sheet.. and all the value from this reference table is take from excel workbook.
    When do you create this Workbook, when does it get changing entries?
    It looks to me as if you would only need the Word-macro that does the stuff with the reference table. In order to get the values from the Excel-workbook into your Word-macro you need to create an Excel-object, open the workbook and read the values.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: [Excel]Passing variable between macro of excel and word

    the table in workbook is create by macro and can be customized by user.
    i never think about that macro in word document can read the value from an excel, i'll try to do in this way...is a macro in word document can fully control an excel workbook?
    that's another question have to ask, do i able to create a control(label, command button) at run time in VBA same like in VB? i tried it quite a long time but can get any command to do that.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel]Passing variable between macro of excel and word

    the code will vary depending where you want to put the controls, on a form, toolbar or in the document? do you already have form?

    buttons on a form are not the same as in the document, and toolbar buttons are different again
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: [Excel]Passing variable between macro of excel and word

    I already have a form, so i intend to put the controls on the form.
    Somemore there is a multipage on my form, and each page will have a frame, the controls will be put on certain frame on a certain page, is possible to do that?

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel]Passing variable between macro of excel and word

    it is quite easy to create a new control, but in vba there is no way i know to set the container to be the frame as you can with VB controls
    you may have to just set the controls as visible or not depending which frame is showing

    vb Code:
    1. Dim c As CommandButton
    2. Set c = UserForm1.Controls.add("Forms.CommandButton.1", "cmdtest", True)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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