+ Reply to Thread
Results 1 to 8 of 8

Coding Cmd Button in userform

Hybrid View

  1. #1
    Registered User
    Join Date
    04-03-2009
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    Coding Cmd Button in userform

    I am trying to figure out how to do the coding for a command button in a userform I've created. It has 5 textbox fields. I want the command button when clicked to transfer the data in those 5 fields to 5 specific cells in a hidden sheet. Then I also want that button to launch a word document.

    Anyone know how I can go about this or where I can go that explains the specific coding?

    I've tried searching with mixed confusing results & read through http://www.contextures.com/xlUserForm01.html#Top & http://www.theofficeexperts.com/down...ExcelDownloads examples.

    Thanks in advance

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Help Coding Cmd Button in userform

    Welcome to the Forum!

    Private Sub CommandButton1_Click()
      Worksheets("Sheet2").Range("A1").Value = TextBox1.Value
      'etc. for others
      Shell "cmd /c winword " & """" & "X:\MSWord\test.doc" & """", vbNormalFocus
      Unload Me
    End Sub

  3. #3
    Registered User
    Join Date
    04-03-2009
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    Re: Help Coding Cmd Button in userform

    I did a quick trial and while I didn't get any errors nothing seemed to happen.

    This is what I have.

    Private Sub CommandButton1_Click()
      Worksheets("Sheet3").Range("B2").Value = lstName.Value
      'etc. for others
      Shell "cmd /c winword " & """" & "C:\test.txt" & """", vbNormalFocus
      Unload Me
    End Sub
    
    Private Sub CmdOrder_Click()
    
    End Sub
    What did I enter wrong?

    Thanks for the help BTW!

  4. #4
    Registered User
    Join Date
    04-03-2009
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    Re: Help Coding Cmd Button in userform

    OK, I reentered it as

    Private Sub CmdOrder_Click()
    Worksheets("Patient").Range("B2").Value = lstName.Value
      'etc. for others
      Shell "cmd /c winword " & """" & "C:\test.txt" & """", vbNormalFocus
      Unload Me
    End Sub
    It works! Thanks a million!

    However, I notice the cmd window pops up, is there a way to kill it after it launches the document?

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Help Coding Cmd Button in userform

    You can hide it.
    Shell "cmd /c winword " & """" & "x:\MSWord\Test.doc" & """", vbHide

  6. #6
    Registered User
    Join Date
    04-03-2009
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    Re: Help Coding Cmd Button in userform

    Quote Originally Posted by Kenneth Hobson View Post
    You can hide it.
    Shell "cmd /c winword " & """" & "x:\MSWord\Test.doc" & """", vbHide
    BTW, thank you so much! It is working perfectly now!

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help Coding Cmd Button in userform

    OP forgot to post his crosslink.

    http://www.mrexcel.com/forum/showthread.php?t=382174
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  8. #8
    Registered User
    Join Date
    04-03-2009
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    15

    Re: Help Coding Cmd Button in userform

    Quote Originally Posted by JBeaucaire View Post
    I posted on that forum first and after several hours and bumps I got no replies. Was it wrong of me to try here?

    I would have mentioned in the OP, but I tried to keep it clutter free since it would have no relevance with no one else contributing over there.
    Last edited by Karkas; 04-03-2009 at 08:23 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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