LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 896
Default Get Data from Word to Excel

it would be better to insert Exit For in the loop after the first dot
is found in "If Mid(wiersz, j, 1) = "." Then", cause a dot may also be
in the end of a this same "numeric" paragraph thus causing some
confusion




On 24 Maj, 18:16, Francis wrote:
Hi Jarek

No problem, I can tweak the codes to suit my requirements

--
Hope this is helpful

Pls click the Yes button below if this post provide answer you have asked

Thank You

cheers, francis

Am not a greek but an ordinary user trying to assist another



"Jarek Kujawa" wrote:
seems this macro works only in thisparticular case = when all a) b)
c)... are in the same paragraph


On 24 Maj, 07:05, Francis wrote:
Hi Jarek


Thanks. and yes, I do need them in english


--
Hope this is helpful


Pls click the Yes button below if this post provide answer you have asked


Thank You


cheers, francis


Am not a greek but an ordinary user trying to assist another


"Jarek Kujawa" wrote:
am not sure if this is exactly what you're seeking but it works on my
Office 2007
surely it might be simpler but at the moment I cannot come up with
anything better. let me know if you need variables and descriptions in
English.
--------
pls click YES if this helped
--------


Sub cus()
Dim wrd As Word.Application
Dim myrange As Word.Range
Dim wiersz As String
Dim numer_pytania As String
Dim tekst_pytania As String
Dim numer_PODpytania As String
Dim tekst_PODpytania As String
Dim pytanie As Integer
Dim PODpytanie As Integer


On Error Resume Next


ActiveSheet.UsedRange.Clear


Set wrd = New Word.Application
wrd.DisplayAlerts = wdAlertsNone


With wrd
..Documents.Open Filename:="C:\Eksele\przyklad.docx",
ConfirmConversions:=False, _
Â* Â* Â* Â* ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
Â* Â* Â* Â* PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
Â* Â* Â* Â* WritePasswordTemplate:="", Format:=wdOpenFormatAuto,
XMLTransform:=""
Dim ten_dok As Word.Document
Set ten_dok = .ActiveDocument


For i = 1 To 20 Â* Â*'ten_dok.Paragraphs.Count


PODpytanie = 2


a = .ActiveDocument.Paragraphs(i).Range.Start
a1 = .ActiveDocument.Paragraphs(i).Range.End


Set myrange = ten_dok.Range(Start:=a, End:=a1)


wiersz = myrange.Text


myrange.Select
myrange.Copy


'określ czy dany wiersz zawiera numer pytania
For j = 1 To Len(wiersz)
If Mid(wiersz, j, 1) = "." Then
pytanie = pytanie + 1
Â* Â* numer_pytania = Left(wiersz, j - 1)
Â* Â* tekst_pytania = Right(wiersz, Len(wiersz) - j)
Â* Â* pytanie = pytanie + 1
Â* Â* ActiveSheet.Cells(pytanie, 1) = numer_pytania
Â* Â* ActiveSheet.Cells(pytanie, 2) = tekst_pytania


'idziesz do kolejnego paragrafu
a = .ActiveDocument.Paragraphs(i + 1).Range.Start
a1 = .ActiveDocument.Paragraphs(i + 1).Range.End
Set myrange = ten_dok.Range(Start:=a, End:=a1)
wiersz = myrange.Text


Â* Â* Â* Â* 'okreÅ›l czy dany wiersz zawiera numer PODpytania
Â* Â* Â* Â* For k = 1 To Len(wiersz)
Â* Â* Â* Â* If Mid(wiersz, k, 1) = ")" Then
'wyszukaj kolejny nawias
Â* Â* Â* Â* Â* Â* tekst_PODpytania = Right(wiersz, Len(wiersz) - k)
Â* Â* Â* Â* Â* Â* PODpytanie = PODpytanie + 1
Â* Â* Â* Â* Â* Â* ActiveSheet.Cells(pytanie, PODpytanie) = tekst_PODpytania


Â* Â* Â* Â* Â* Â* For l = 1 To Len(tekst_PODpytania & ")")
Â* Â* Â* Â* Â* Â* Â* Â* If Mid(tekst_PODpytania & ")", l, 1) = ")" Then
Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* znajdz_kolejny_nawias = l
Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Exit For
Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* End If
Â* Â* Â* Â* Â* Â* Next l


Â* Â* Â* Â* Â* Â* If k + Len(tekst_PODpytania) = Len(wiersz) Then
Â* Â* Â* Â* Â* Â* Â* Â* ActiveSheet..Cells(pytanie, PODpytanie) = Mid
(tekst_PODpytania, 1, znajdz_kolejny_nawias - 2)
Â* Â* Â* Â* Â* Â* Else
Â* Â* Â* Â* Â* Â* Â* Â* Exit For
Â* Â* Â* Â* Â* Â* End If


Â* Â* Â* Â* End If


Â* Â* Â* Â* Next k


Â* Â* Exit For
End If
Next j


Next i
End With


ten_dok.Close
wrd.Quit
Set wrd = Nothing


End Sub


On 23 Maj, 12:30, Francis wrote:
Pls ignore my earlier as I press enter too fast.


I have a Word document which contents shows as :


1.Apart from formal legal education, what alternative qualification is
necessary for a legal assistant?


a)a qualification in a related discipline
b)there is no alternative
c)many years of practical experience
d)membership with a recognized association


2.Who supervises a legal assistants work?


a)the Supreme Court
b)the Managing Director
c)a notary public
d)an attorney
e)no one


How do I import these to give me :
Col A = question number
Col B = questions
Col C = answer a)
Col D = answer b)
Col E = answer c)
Col F = answer d)
Col G = answer e)


TIA
--
Hope this is helpful


Pls click the Yes button below if this post provide answer you have asked


Thank You


cheers, francis


Am not a greek but an ordinary user trying to assist another- Ukryj cytowany tekst -


- Pokaż cytowany tekst -- Ukryj cytowany tekst -


- Pokaż cytowany tekst -


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get data from Word into Excel Moprem Excel Discussion (Misc queries) 2 February 23rd 08 12:00 AM
Copy excel data (inc. textbox data) into Word Sarah (OGI) Excel Discussion (Misc queries) 0 August 14th 07 05:00 PM
Transfer Excel data into Word, including text box data Sarah (OGI) Excel Discussion (Misc queries) 0 July 13th 07 10:06 AM
I want to convert word column data to excel row data to sort addre craywill Excel Discussion (Misc queries) 0 April 18th 06 07:16 PM
Print labels by using Excel data in a Word mail into word Zoey Excel Discussion (Misc queries) 1 November 1st 05 09:08 PM


All times are GMT +1. The time now is 09:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"