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.
excel vba excel-vba userform bookmarks
|
show 1 more comment
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.
excel vba excel-vba userform bookmarks
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
|
show 1 more comment
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.
excel vba excel-vba userform bookmarks
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
excel vba excel-vba userform bookmarks
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
|
show 1 more comment
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
|
show 1 more comment
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered 2 days ago
Kev
14
14
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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