Results 1 to 16 of 16

Thread: Solved: Dropdown FormField Inserting Files

  1. #1
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location

    Solved: Dropdown FormField Inserting Files

    Hi, hope you can help! Im a bit new to this

    I have created a form on word using Dropdown and Text Formfields. I have the following macro running on exit in a Dropdown Formfield (Dropdown1). How can i get it to insert the text from the file in a Text Formfield (Text1) instead of at the end of the document??


    [vba]Sub DropSelection()
    Dim myrange As Range
    ActiveDocument.Unprotect
    Set myrange = ActiveDocument.Range
    myrange.Collapse wdCollapseEnd
    myrange.InsertFile "C:\Documents and Settings\pwilliams\My Documents\" & _
    ActiveDocument.FormFields("DropDown1").DropDown.Value & ".doc"
    ActiveDocument.Protect wdAllowOnlyFormFields, NoReset
    End Sub[/vba]


    Many Thanks
    Pete
    Last edited by BlueCactus; 04-28-2005 at 06:18 AM. Reason: Added VBA tags

  2. #2
    VBAX Regular TButhe's Avatar
    Joined
    Sep 2004
    Location
    Sioux Falls, SD
    Posts
    64
    Location
    Hi,

    Check out this thread, if I am understanding you correctly this may help. http://www.vbaexpress.com/forum/showthread.php?t=1996

    If this isn't what you need just post back I KNOW someone here can help. They always manage to sort out my messes!!

    Have a great day!! Tracy
    Last edited by TButhe; 04-28-2005 at 07:54 AM. Reason: spelling

  3. #3
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location
    This only seems to tell me how to insert text from within the same document.

    I need to know how to insert text from another word document into my current word document. I need this text to drop into a text formfield. Also i need it to be activated by a Dropdown formfield.

    I hope someone can help!

  4. #4
    VBAX Regular
    Joined
    Nov 2004
    Posts
    74
    Location
    Hi Pete,

    How are you fairing up? It's a nightmare when you get stuck!

    Please could you attach an copy of your document and I'll try and help.

    Kieran

  5. #5
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi Pete,

    You use the "InsertFile" method with "myrange". Previously, you set myrange to the end of the document[VBA]Set myrange = ActiveDocument.Range
    myrange.Collapse wdCollapseEnd[/VBA]so what you need to do instead is set myrange to the range of your target instead (the text formfield)[VBA]'where "Text1" is the name of your text form field
    Set myRange = ActiveDocument.FormFields("Text1").Range
    myRange.InsertFile "C:\Documents... etc, etc..."
    [/VBA]
    K :-)

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by Killian
    Hi Pete,
    so what you need to do instead is set myrange to the range of your target instead (the text formfield)[VBA]'where "Text1" is the name of your text form field
    Set myRange = ActiveDocument.FormFields("Text1").Range
    myRange.InsertFile "C:\Documents... etc, etc..."
    [/VBA]
    Hi K,

    This code will overwrite the range of the formfield so the field is no longer available for editing! (It's in the protected section of the document now as plain text)

    Perhaps this is what Pete's after but it seams to me he want the contents off that file in the formfield so he can edit it some more.

    So Pete can you clarify what you want?
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  7. #7
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location
    MOS MASTER,

    You are correct, i do need the contents of the file to appear in the formfield (as apposed to overwriting the formfield).

    Hope you can come up with a solution to this.

    Many Thanks

    Pete

  8. #8
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Good call Joost!
    If the field is still required afterwards then you need to return a range object from inside the text field to apply the insert file method. The simplest (and admittedly least elegant) way of doing that is to move the selection object in there[VBA]ActiveDocument.FormFields("Text1").Select
    Selection.MoveLeft wdCharacter, 1
    Selection.MoveRight wdCharacter, 1
    Selection.InsertFile "C:\ etc, etc..."[/VBA]
    K :-)

  9. #9
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location
    Thanks Killian,

    That worked fine for me.

    Also, i would like to run a macro on entry to a dropdown formfield that left clicks on the dropdown menu for me.

    I know that the syntax is: FieldObject.DoClick

    I hope you can help me on this.

    Thanks again
    Pete

  10. #10
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    np Pete,

    You can either set the exit macro when you create the dropdown or with VBA[VBA]ActiveDocument.FormFields("Dropdown1").ExitMacro = "Macro1"[/VBA]
    K :-)

  11. #11
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location
    That doesn't answer my question. I have a Dropdown Formfield (Dropdown1) and i require a Macro that i can set to Run On Entry.

    The macro i require needs to left click on the Dropdown Formfield for me?
    Do you get what i mean? It's quite hard to explain

    Pete

  12. #12
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    As far as I'm aware. you can have a marco run when you enter the dropdown and when you exit.
    these are set with the "EntryMacro" and "ExitMacro" properties of the specified formfield object.
    I've noticed that the Entry marco fires when you arrow key or tab down to the dropdown, but doesn't when you select it directly by left-clicking. It seems to skip the "enrty" part and go straight to dropping down (for which there is no event).
    This is the kind of flakey behaviour I've come to expect from Word. Is that a problem?
    K :-)

  13. #13
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Killian,

    Thanx!

    You're right there is now dropdown property to show the list om a formfield dropdown.

    @pete,

    However you can simulate the keystrokes with the Sendkeys method.

    This works for me in a entry macro:[VBA]
    Sub DropDownList()
    SendKeys "%{DOWN}", True
    End Sub
    [/VBA]

    It presses ALT+Arrow down to open the list!

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  14. #14
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location
    You guy's are great!

    Thank you, thank you, thank you!!!!!

    Pete

  15. #15
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    You're Welcome!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  16. #16
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by petedw
    You guy's are great!

    Thank you, thank you, thank you!!!!!

    Pete
    Hi Pete,

    Almost forgotten...could you mark you're thread solved?
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •