Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2017, 07:05 AM
mihnea96 mihnea96 is offline how to copy different text from word into excel on consecutive rows Windows 7 32bit how to copy different text from word into excel on consecutive rows Office 2010 32bit
Novice
how to copy different text from word into excel on consecutive rows
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default how to copy different text from word into excel on consecutive rows

Hi! Could you kindly help me with my problem: I want to copy some text from Word into Excel, using a command button. The idea is that i select some text, press the button and it pastes the selected text in b2, for example, and when I select another text, I cannot make it to paste the secondly selected text in b3, and so on.


This is the code i'm trying to use. Could you explain me, please, what's wrong about it and help me fix it?

Thank you!

Code:
Private Sub CommandButton2_Click()
Selection.Copy
Dim objXL As Object
Set objXL = GetObject(, "excel.application")

Dim NumRows As Long
Dim xlsRow As Row
xlsRow = xlsRow + 1
objXL.Application.Cells(xlsRow, 2) = Selection.Text
Selection.Paste

End Sub
Reply With Quote
  #2  
Old 05-08-2017, 07:58 AM
gmayor's Avatar
gmayor gmayor is offline how to copy different text from word into excel on consecutive rows Windows 10 how to copy different text from word into excel on consecutive rows Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,104
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Assuming the workbook is open at the sheet you want to process then

Code:
Private Sub CommandButton2_Click()
Dim objXL As Object
Dim NumRows As Long
Dim xlsNextRow As Long
Dim xlSheet As Object
    If Len(Selection) > 1 Then
        Set objXL = GetObject(, "excel.application")
        Set xlSheet = objXL.activesheet
        xlsNextRow = xlSheet.Range("B" & xlSheet.Rows.Count).End(-4162).Row + 1
        xlSheet.Cells(xlsNextRow, 2) = Selection.Text
    Else
        MsgBox "Nothing selected"
    End If
    Set objXL = Nothing
    Set xlSheet = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-08-2017, 08:20 AM
mihnea96 mihnea96 is offline how to copy different text from word into excel on consecutive rows Windows 7 32bit how to copy different text from word into excel on consecutive rows Office 2010 32bit
Novice
how to copy different text from word into excel on consecutive rows
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

It works perfectly! Thank you very much!
Would it be too much if I'd ask how to make it bold?
Reply With Quote
  #4  
Old 05-08-2017, 10:06 AM
gmayor's Avatar
gmayor gmayor is offline how to copy different text from word into excel on consecutive rows Windows 10 how to copy different text from word into excel on consecutive rows Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,104
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Add
Code:
xlSheet.Cells(xlsNextRow, 2).Font.Bold = True
immediately before 'Else' i.e.
Code:
    xlSheet.Cells(xlsNextRow, 2) = Selection.Text
        xlSheet.Cells(xlsNextRow, 2).Font.Bold = True
    Else
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 05-08-2017, 12:09 PM
mihnea96 mihnea96 is offline how to copy different text from word into excel on consecutive rows Windows 7 32bit how to copy different text from word into excel on consecutive rows Office 2010 32bit
Novice
how to copy different text from word into excel on consecutive rows
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

It works great! Thank you very much!
Reply With Quote
Reply

Tags
word to excel text



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to copy different text from word into excel on consecutive rows Excel VBA macro to copy specific rows and delete it pourmalla Excel Programming 2 04-02-2017 12:09 AM
Counting Consecutive Periods In Rows Using Numbers Yaaseen23 Excel 18 03-24-2017 11:15 AM
Copy Underline text from Word and Paste into excel rfaris Excel Programming 7 10-05-2015 05:56 AM
how to copy different text from word into excel on consecutive rows Is it possible to copy non-contiguous rows of a Table and paste them as a separate Table in Word? Joey Cheung Word Tables 1 08-12-2014 05:15 PM
how to copy different text from word into excel on consecutive rows Find Results in excel copy the rows to another sheet khalidfazeli Excel 2 02-06-2013 09:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft