?
Solved

Copy word table, paste into excel, simple?

Posted on 2004-04-30
13
Medium Priority
?
5,043 Views
Last Modified: 2012-05-04
Hey guys and gals,

Here's my problem, one of my partners created this 75 page MS Word table. Each cell has a blob of text with hard returns in it. I tried to copy the word table and paste it into excel, but wherever there is a hard return, the text goes to the next cell in excel and the formatting gets screwed up. Here's a list of stuff I already tried with no success:

1. Tried converting it to tab delimited and then importing to excel.
2. Copied whole table and pasted into excel
3. Downloaded a program called Word2Excel Converter
4.  Did the paste special thing in excel and chose "Keep original formatting"
None of these things worked...

Is there a VBA program or something out there that I can use? Any other ideas/suggestions are welcome, I am pulling my hair out trying to figure this out...

Thanks everyone!

-Steve
0
Comment
Question by:Venturer58
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 16

Expert Comment

by:sebastienm
ID: 10965363
Hi Steve,
1. Should these hard Returns be considered in Excel as:
   - word wrap within a single cell
   -or real enter within a single cell
   ?
2. Do you have a visible border around each cell in the Word table? or not always? When pasting top excel, hard returns becomes separate cells, but these cells dont have a top-horizontal border, they could therefore be tracked that way in a macro.

Regards,
Sebastien
 
0
 
LVL 1

Author Comment

by:Venturer58
ID: 10965421
I would like the hard returns to transfer to a hard return within a single cell. For example:

_____
BLAH |
        |
BLAH |
_____|

in one cell in the MS Word table to:

_____
BLAH |
        |
BLAH |
_____|

in the excel cell.

Does this answer your question?
0
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 1000 total points
ID: 10966060
Steve,

execute this form your word document. The code selects the first table in the document, replaces all carrage returns with the text "myCreturn" then copies the table over to xl and then replaces all "myCreturn" back to carrage return.

----------------------
Sub wrdTOxl()
Dim xlApp As Object, xlSht As Object, myTbl As Table
Set myTbl = ActiveDocument.Tables(1): myTbl.Select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p": .Replacement.Text = "myCreturn"
.Forward = True: .Wrap = 0
End With
Selection.Find.Execute Replace:=wdReplaceAll
Set xlApp = CreateObject("Excel.Application"): xlApp.Visible = True
Set xlSht = xlApp.Workbooks.Add.Sheets(1)
myTbl.Range.Copy: xlSht.Paste
xlSht.UsedRange.Replace "myCreturn", vbCrLf, 2
Set myTbl = Nothing: Set xlSht = Nothing: Set xlApp = Nothing
End Sub
---------------------


Rajesh
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10966394
if the carriage return?linefeed combination creates strange chars in xl you could replace it with only a linefeed

xlSht.UsedRange.Replace "myCreturn", vbLf, 2
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 10967614
Search and replace hard return ^p with a space?  That's what I've done in the past.
0
 
LVL 1

Author Comment

by:Venturer58
ID: 10972019
Okay guys, we're almost there, I used your code above and got everything into excel almost correctly, but it gave the error msg "Formula too long" and instead of carraige returns, it inserted "myCreturn" where the hard returns should be... any way to replace "myCreturn" with a carraige return? If so, we're good to go...

Thanks!!

-Steve
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10972134
Steve,

how long is the biggest string in the word table???

anyway try this modified code:

Sub wrdTOxl()
Dim xlApp As Excel.Object, xlSht As Excel.Object, myTbl As Table
Set myTbl = ActiveDocument.Tables(1): myTbl.Select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = "^p": .Replacement.text = "myCreturn"
.Forward = True: .Wrap = 0
End With
Selection.Find.Execute Replace:=wdReplaceAll
Set xlApp = CreateObject("Excel.Application"): xlApp.Visible = True
Set xlSht = xlApp.Workbooks.Add.Sheets(1)
myTbl.Range.Copy
xlSht.Cells.NumberFormat = "@"
xlSht.Paste
xlSht.Cells.NumberFormat = "@"
'On Error Resume Next
xlSht.UsedRange.Replace "myCreturn", vbLf, 2
'On Error GoTo 0
Set myTbl = Nothing: Set xlSht = Nothing: Set xlApp = Nothing
End Sub


if you still get the error, run this sub form xl once the table has been transfered there.

Sub test1()
Cells.Replace What:="myCreturn", Replacement:=vbLf, LookAt:=xlPart
End Sub


Rajesh
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10972140
oops... the second line in the above code should be this:
Dim xlApp As Object, xlSht As Object, myTbl As Table

R
0
 
LVL 1

Author Comment

by:Venturer58
ID: 10972329
almost worked... alright, I ran your very first block of code and that was great, everything transferred formatted as I needed it, except "myCReturn" was where the carraige returns should have been, so what I did was do a Find/Replace all "myCreturn" with a carraige return, and that worked for every cell, except the cells (about 50 cells) that had really long text strings in them. I got the error "Formula too long" message when trying to do a find/replace into these cell. I tried reformatting the cells to "Text", but this just changed my text fields to "####" and when i went to make the field wider all I saw was more # signs.

I ran your second block of code and I got # signs for all of my fields except a few... So I am now manually finding and replacing every "myCreturn" in the cells that have a ton of text in them... I tried to run this:

Sub test1()
Cells.Replace What:="myCreturn", Replacement:=vbLf, LookAt:=xlPart
End Sub

but it didn't seem to do anything...

Is there a way in excel to find all of the myCreturn's and replace them with carraige returns? Thanks so much!

-Steve
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10972389
Hi steve,
sorry, I am going out for couple of hours...
Any possibility of me getting a chance to look at you word doc. Email id is in my profile

R
0
 
LVL 1

Author Comment

by:Venturer58
ID: 10972637
I apologize, I can't e-mail it to you, it's corporate confidential information... I work for a consulting firm and the document is an audit program for one of our clients.

I will continue to manually find and replace the myCreturn's and if you have any other ideas, please post them. If I finish over the next couple of hours, i'll accept your (R. Rajesh) comment as the answer, you saved me hours worth of work already. Thanks again!

-Steve
0
 
LVL 1

Author Comment

by:Venturer58
ID: 10972698
Got it, whohooo!
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10987253
hi steve,
sorry we couldn't nail the replacing bit.
thanks for the grade :)
R
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question