+ Reply to Thread
Results 1 to 9 of 9

Passing a variable from userform to module code - value being dropped or not seen

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Passing a variable from userform to module code - value being dropped or not seen

    I am trying to print word documents from an excel userform which lists documents as radio buttons captions. When radio button selected I can see the document name as "SelectedOption" in a message box. When I then start a module code "automateword" the value of "SelectedOption" is dropped. How can I pass it on??

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by nigelog; 06-22-2018 at 05:04 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Passing a variable from userform to module code - value being dropped or not seen

    Where have you declared SelectedOption?

    By the way, have you considered reading the value(s) directly from the userform in the automateword sub?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,343

    Re: Passing a variable from userform to module code - value being dropped or not seen

    Or set a Global variable.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Passing a variable from userform to module code - value being dropped or not seen

    Hi Norie
    thanks, I forgot to Dim as String...works now but I'll have a look at your option

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Passing a variable from userform to module code - value being dropped or not seen

    @Bakerman
    I might take this opportunity to learn about global variables...Ta

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Passing a variable from userform to module code - value being dropped or not seen

    You should simply pass the variable as an argument, rather than using a public variable or back referencing the userform

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Passing a variable from userform to module code - value being dropped or not seen

    @Andy
    A lot of options - I often wondered what the bracketed expressions were on a sub title.
    I'll have a look through all suggestions to familiarise myself

    all I need to find now is to add "If word document already open option"

    Thanks all for the help

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,343

    Re: Passing a variable from userform to module code - value being dropped or not seen

    Nigelog, thanks for rep+.

    Something like this.
    Please Login or Register  to view this content.
    GetObject checks wether Word is open, if not CreateObject takes over.

    But I'd suggest you start a new thread if you want to continue on this subject.

  9. #9
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Passing a variable from userform to module code - value being dropped or not seen

    No problem

    thanks Bakerman

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Place code in userform, module or class module
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2017, 07:04 AM
  2. Advice on passing userform parameters to a vba class module
    By techno_gronk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2017, 06:13 AM
  3. Replies: 0
    Last Post: 03-08-2014, 08:02 AM
  4. Passing variable value from Private Sub to Module
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2009, 08:38 AM
  5. Passing variables and values between sheet code and module code
    By imux in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-14-2009, 12:23 PM
  6. Passing a private variable to another module
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-26-2008, 02:26 PM
  7. Passing variable from userform to module error
    By mworth01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2005, 12:47 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1