VBA Excel - add userform textbox value to worksheet











up vote
0
down vote

favorite












Private Sub Submit_Click()

'----------The Script below writes values to Word Doc ----------------------------------------

Dim wApp As Object
Dim wDoc As Object

'We need to continue through errors since if Word isn't
'open the GetObject line will give an error

'On Error Resume Next
Set wApp = GetObject(, "Word.Application")


'We've tried to get Word but if it's nothing then it isn't open
If wApp Is Nothing Then
Set wApp = CreateObject("Word.Application")
End If

'It's good practice to reset error warnings
On Error GoTo 0

'Open your document and ensure its visible and activate after opening

Set wDoc = wApp.Documents.Open(Filename:="C:Documentsexample.docx ", ReadOnly:=False)
With wDoc
.Bookmarks("bookmark1").Range.Text = Me.TextBox1.Value 'how do I also insert the TextBox1.Value to the next empty row in worksheet?

'so far I got this to do it but everytime i click submit it puts it in the same cell instead of the next row

Sheet6.Range("H2").Value = Me.TextBox6.Value

End With

wApp.Visible = True

'set default file name and file path

ProposedFileName = Format(Now(), "DDMMMYYYY") & TextBox1.Value & "-" & ".doc"
ProposedFilePath = "C:Documents"

With wApp.FileDialog(msoFileDialogSaveAs)
wDoc.SaveAs2 ProposedFilePath & ProposedFileName, _
FilterIndex = 1, _
FileFormat:=wdFormatDocument

End With
End Sub


Hi all,



The code above is just a part of my script which works fine when the userform textbox value gets inserted to bookmark1 in word doc, but how do I also insert this textbox value to worksheet row for example goes under column header "name"?



Thank you.










share|improve this question
























  • This code is from Userform?
    – Nelman Jay Louie Vasquez
    Nov 10 at 9:45










  • @NELMVN yes it is
    – Kev
    Nov 10 at 9:52










  • range.cells(C, 2).Value = Me.TextBox1.Value
    – Kev
    Nov 10 at 9:57










  • @NELMVN would it be something like this code?
    – Kev
    Nov 10 at 9:57










  • Can you post the your whole Code
    – Nelman Jay Louie Vasquez
    Nov 10 at 10:05















up vote
0
down vote

favorite












Private Sub Submit_Click()

'----------The Script below writes values to Word Doc ----------------------------------------

Dim wApp As Object
Dim wDoc As Object

'We need to continue through errors since if Word isn't
'open the GetObject line will give an error

'On Error Resume Next
Set wApp = GetObject(, "Word.Application")


'We've tried to get Word but if it's nothing then it isn't open
If wApp Is Nothing Then
Set wApp = CreateObject("Word.Application")
End If

'It's good practice to reset error warnings
On Error GoTo 0

'Open your document and ensure its visible and activate after opening

Set wDoc = wApp.Documents.Open(Filename:="C:Documentsexample.docx ", ReadOnly:=False)
With wDoc
.Bookmarks("bookmark1").Range.Text = Me.TextBox1.Value 'how do I also insert the TextBox1.Value to the next empty row in worksheet?

'so far I got this to do it but everytime i click submit it puts it in the same cell instead of the next row

Sheet6.Range("H2").Value = Me.TextBox6.Value

End With

wApp.Visible = True

'set default file name and file path

ProposedFileName = Format(Now(), "DDMMMYYYY") & TextBox1.Value & "-" & ".doc"
ProposedFilePath = "C:Documents"

With wApp.FileDialog(msoFileDialogSaveAs)
wDoc.SaveAs2 ProposedFilePath & ProposedFileName, _
FilterIndex = 1, _
FileFormat:=wdFormatDocument

End With
End Sub


Hi all,



The code above is just a part of my script which works fine when the userform textbox value gets inserted to bookmark1 in word doc, but how do I also insert this textbox value to worksheet row for example goes under column header "name"?



Thank you.










share|improve this question
























  • This code is from Userform?
    – Nelman Jay Louie Vasquez
    Nov 10 at 9:45










  • @NELMVN yes it is
    – Kev
    Nov 10 at 9:52










  • range.cells(C, 2).Value = Me.TextBox1.Value
    – Kev
    Nov 10 at 9:57










  • @NELMVN would it be something like this code?
    – Kev
    Nov 10 at 9:57










  • Can you post the your whole Code
    – Nelman Jay Louie Vasquez
    Nov 10 at 10:05













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Private Sub Submit_Click()

'----------The Script below writes values to Word Doc ----------------------------------------

Dim wApp As Object
Dim wDoc As Object

'We need to continue through errors since if Word isn't
'open the GetObject line will give an error

'On Error Resume Next
Set wApp = GetObject(, "Word.Application")


'We've tried to get Word but if it's nothing then it isn't open
If wApp Is Nothing Then
Set wApp = CreateObject("Word.Application")
End If

'It's good practice to reset error warnings
On Error GoTo 0

'Open your document and ensure its visible and activate after opening

Set wDoc = wApp.Documents.Open(Filename:="C:Documentsexample.docx ", ReadOnly:=False)
With wDoc
.Bookmarks("bookmark1").Range.Text = Me.TextBox1.Value 'how do I also insert the TextBox1.Value to the next empty row in worksheet?

'so far I got this to do it but everytime i click submit it puts it in the same cell instead of the next row

Sheet6.Range("H2").Value = Me.TextBox6.Value

End With

wApp.Visible = True

'set default file name and file path

ProposedFileName = Format(Now(), "DDMMMYYYY") & TextBox1.Value & "-" & ".doc"
ProposedFilePath = "C:Documents"

With wApp.FileDialog(msoFileDialogSaveAs)
wDoc.SaveAs2 ProposedFilePath & ProposedFileName, _
FilterIndex = 1, _
FileFormat:=wdFormatDocument

End With
End Sub


Hi all,



The code above is just a part of my script which works fine when the userform textbox value gets inserted to bookmark1 in word doc, but how do I also insert this textbox value to worksheet row for example goes under column header "name"?



Thank you.










share|improve this question















Private Sub Submit_Click()

'----------The Script below writes values to Word Doc ----------------------------------------

Dim wApp As Object
Dim wDoc As Object

'We need to continue through errors since if Word isn't
'open the GetObject line will give an error

'On Error Resume Next
Set wApp = GetObject(, "Word.Application")


'We've tried to get Word but if it's nothing then it isn't open
If wApp Is Nothing Then
Set wApp = CreateObject("Word.Application")
End If

'It's good practice to reset error warnings
On Error GoTo 0

'Open your document and ensure its visible and activate after opening

Set wDoc = wApp.Documents.Open(Filename:="C:Documentsexample.docx ", ReadOnly:=False)
With wDoc
.Bookmarks("bookmark1").Range.Text = Me.TextBox1.Value 'how do I also insert the TextBox1.Value to the next empty row in worksheet?

'so far I got this to do it but everytime i click submit it puts it in the same cell instead of the next row

Sheet6.Range("H2").Value = Me.TextBox6.Value

End With

wApp.Visible = True

'set default file name and file path

ProposedFileName = Format(Now(), "DDMMMYYYY") & TextBox1.Value & "-" & ".doc"
ProposedFilePath = "C:Documents"

With wApp.FileDialog(msoFileDialogSaveAs)
wDoc.SaveAs2 ProposedFilePath & ProposedFileName, _
FilterIndex = 1, _
FileFormat:=wdFormatDocument

End With
End Sub


Hi all,



The code above is just a part of my script which works fine when the userform textbox value gets inserted to bookmark1 in word doc, but how do I also insert this textbox value to worksheet row for example goes under column header "name"?



Thank you.







excel vba excel-vba userform bookmarks






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 7:19









Pᴇʜ

20.1k42650




20.1k42650










asked Nov 10 at 9:39









Kev

34




34












  • This code is from Userform?
    – Nelman Jay Louie Vasquez
    Nov 10 at 9:45










  • @NELMVN yes it is
    – Kev
    Nov 10 at 9:52










  • range.cells(C, 2).Value = Me.TextBox1.Value
    – Kev
    Nov 10 at 9:57










  • @NELMVN would it be something like this code?
    – Kev
    Nov 10 at 9:57










  • Can you post the your whole Code
    – Nelman Jay Louie Vasquez
    Nov 10 at 10:05


















  • This code is from Userform?
    – Nelman Jay Louie Vasquez
    Nov 10 at 9:45










  • @NELMVN yes it is
    – Kev
    Nov 10 at 9:52










  • range.cells(C, 2).Value = Me.TextBox1.Value
    – Kev
    Nov 10 at 9:57










  • @NELMVN would it be something like this code?
    – Kev
    Nov 10 at 9:57










  • Can you post the your whole Code
    – Nelman Jay Louie Vasquez
    Nov 10 at 10:05
















This code is from Userform?
– Nelman Jay Louie Vasquez
Nov 10 at 9:45




This code is from Userform?
– Nelman Jay Louie Vasquez
Nov 10 at 9:45












@NELMVN yes it is
– Kev
Nov 10 at 9:52




@NELMVN yes it is
– Kev
Nov 10 at 9:52












range.cells(C, 2).Value = Me.TextBox1.Value
– Kev
Nov 10 at 9:57




range.cells(C, 2).Value = Me.TextBox1.Value
– Kev
Nov 10 at 9:57












@NELMVN would it be something like this code?
– Kev
Nov 10 at 9:57




@NELMVN would it be something like this code?
– Kev
Nov 10 at 9:57












Can you post the your whole Code
– Nelman Jay Louie Vasquez
Nov 10 at 10:05




Can you post the your whole Code
– Nelman Jay Louie Vasquez
Nov 10 at 10:05












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I have finally managed to solve it by adding the code



Dim LastRow As Long, ws As Worksheet

Set ws = Sheets(2)

LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row

ws.Range("A" & LastRow).Value = TextBox1.Value 'Adds the TextBox1 into Col A & Last Blank Row





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237692%2fvba-excel-add-userform-textbox-value-to-worksheet%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I have finally managed to solve it by adding the code



    Dim LastRow As Long, ws As Worksheet

    Set ws = Sheets(2)

    LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row

    ws.Range("A" & LastRow).Value = TextBox1.Value 'Adds the TextBox1 into Col A & Last Blank Row





    share|improve this answer

























      up vote
      0
      down vote













      I have finally managed to solve it by adding the code



      Dim LastRow As Long, ws As Worksheet

      Set ws = Sheets(2)

      LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row

      ws.Range("A" & LastRow).Value = TextBox1.Value 'Adds the TextBox1 into Col A & Last Blank Row





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I have finally managed to solve it by adding the code



        Dim LastRow As Long, ws As Worksheet

        Set ws = Sheets(2)

        LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row

        ws.Range("A" & LastRow).Value = TextBox1.Value 'Adds the TextBox1 into Col A & Last Blank Row





        share|improve this answer












        I have finally managed to solve it by adding the code



        Dim LastRow As Long, ws As Worksheet

        Set ws = Sheets(2)

        LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1 'Finds the last blank row

        ws.Range("A" & LastRow).Value = TextBox1.Value 'Adds the TextBox1 into Col A & Last Blank Row






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 10:53









        Kev

        34




        34






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237692%2fvba-excel-add-userform-textbox-value-to-worksheet%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff