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?
    – NELMVN
    2 days ago










  • @NELMVN yes it is
    – Kev
    2 days ago










  • range.cells(C, 2).Value = Me.TextBox1.Value
    – Kev
    2 days ago










  • @NELMVN would it be something like this code?
    – Kev
    2 days ago










  • Can you post the your whole Code
    – NELMVN
    2 days ago














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?
    – NELMVN
    2 days ago










  • @NELMVN yes it is
    – Kev
    2 days ago










  • range.cells(C, 2).Value = Me.TextBox1.Value
    – Kev
    2 days ago










  • @NELMVN would it be something like this code?
    – Kev
    2 days ago










  • Can you post the your whole Code
    – NELMVN
    2 days ago












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 21 hours ago









Pᴇʜ

18.3k42549




18.3k42549










asked 2 days ago









Kev

14




14











  • This code is from Userform?
    – NELMVN
    2 days ago










  • @NELMVN yes it is
    – Kev
    2 days ago










  • range.cells(C, 2).Value = Me.TextBox1.Value
    – Kev
    2 days ago










  • @NELMVN would it be something like this code?
    – Kev
    2 days ago










  • Can you post the your whole Code
    – NELMVN
    2 days ago
















  • This code is from Userform?
    – NELMVN
    2 days ago










  • @NELMVN yes it is
    – Kev
    2 days ago










  • range.cells(C, 2).Value = Me.TextBox1.Value
    – Kev
    2 days ago










  • @NELMVN would it be something like this code?
    – Kev
    2 days ago










  • Can you post the your whole Code
    – NELMVN
    2 days ago















This code is from Userform?
– NELMVN
2 days ago




This code is from Userform?
– NELMVN
2 days ago












@NELMVN yes it is
– Kev
2 days ago




@NELMVN yes it is
– Kev
2 days ago












range.cells(C, 2).Value = Me.TextBox1.Value
– Kev
2 days ago




range.cells(C, 2).Value = Me.TextBox1.Value
– Kev
2 days ago












@NELMVN would it be something like this code?
– Kev
2 days ago




@NELMVN would it be something like this code?
– Kev
2 days ago












Can you post the your whole Code
– NELMVN
2 days ago




Can you post the your whole Code
– NELMVN
2 days ago












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






























    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 2 days ago









        Kev

        14




        14



























             

            draft saved


            draft discarded















































             


            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














































































            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto