ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   word to excel format change (https://www.excelbanter.com/excel-programming/427910-word-excel-format-change.html)

[email protected][_2_]

word to excel format change
 
When copied my word table into excel sheet
2-0-0 becomes 2-0-0 which is correct but
2-4-0 becomes 02.04.2000 on excel cell. This is rather irritating.
I have to keep this "-" intact as i am doing parsing afterwards.
Any help or right direction ? Thank you very much in advance.

Part of my code to copy:
.........
wdDoc.Tables(1).Select
wdApp.Selection.Copy: Sh.Paste
wdApp.Quit
.............


Peter T

word to excel format change
 
This worked for me

Sub test()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdTble As Word.Table
Dim ws As Worksheet

Set ws = ActiveSheet
Dim rng As Excel.Range

Set ws = ActiveSheet
Set rng = ws.Range("A1")

Set wdApp = GetObject(, "word.application")
Set wdDoc = wdApp.ActiveDocument

Set wdTble = wdDoc.Tables(1)
With wdTble
Set rng = rng.Resize(.Rows.Count, .Columns.Count)
End With

' must be a way to avoid Select ?
wdTble.Select
wdApp.Selection.Copy

rng.NumberFormat = "@" ' as text

rng.PasteSpecial xlPasteValues

' maybe apply some other formats
With rng.Borders
.LineStyle = xlContinuous
.Weight = xlThin ' xlMedium
End With
rng.HorizontalAlignment = xlRight

End Sub

Regards,
Peter T

wrote in message
...
When copied my word table into excel sheet
2-0-0 becomes 2-0-0 which is correct but
2-4-0 becomes 02.04.2000 on excel cell. This is rather irritating.
I have to keep this "-" intact as i am doing parsing afterwards.
Any help or right direction ? Thank you very much in advance.

Part of my code to copy:
........
wdDoc.Tables(1).Select
wdApp.Selection.Copy: Sh.Paste
wdApp.Quit
............




[email protected][_2_]

word to excel format change
 
On May 3, 12:18*pm, "Peter T" <peter_t@discussions wrote:
This worked for me

Sub test()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wdTble As Word.Table
Dim ws As Worksheet

* * Set ws = ActiveSheet
* * Dim rng As Excel.Range

* * Set ws = ActiveSheet
* * Set rng = ws.Range("A1")

* * Set wdApp = GetObject(, "word.application")
* * Set wdDoc = wdApp.ActiveDocument

* * Set wdTble = wdDoc.Tables(1)
* * With wdTble
* * * * Set rng = rng.Resize(.Rows.Count, .Columns.Count)
* * End With

' must be a way to avoid Select ?
* * wdTble.Select
* * wdApp.Selection.Copy

* * rng.NumberFormat = "@" ' as text

* * rng.PasteSpecial xlPasteValues

* * ' maybe apply some other formats
* * With rng.Borders
* * * * .LineStyle = xlContinuous
* * * * .Weight = xlThin ' xlMedium
* * End With
* * rng.HorizontalAlignment = xlRight

End Sub

Regards,
Peter T

wrote in message

...



When copied my word table into excel sheet
2-0-0 becomes 2-0-0 which is correct but
2-4-0 becomes 02.04.2000 on excel cell. This is rather irritating.
I have to keep this "-" intact as i am doing parsing afterwards.
Any help or right direction ? Thank you very much in advance.


Part of my code to copy:
........
wdDoc.Tables(1).Select
wdApp.Selection.Copy: Sh.Paste
wdApp.Quit
............- Hide quoted text -


- Show quoted text -


Worked charmingly !

Thank you very much Peter.


All times are GMT +1. The time now is 02:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com