PDA

View Full Version : [SOLVED:] handle file between Word & Excel in VBA



Ethen5155
01-11-2017, 02:11 AM
Hi all,

well i have many files to handle between Word and Excel with a specific structure

as you see below i want to copy all Green segments then generate an Excel file in same path and copy it to column (A)
then copy all Yellow segments to same file but at column (B)

17993


after that when i finish some modifications at excel i want to copy them back to word file with same structure:
Column (A) --> goes to Green
Column (B) --> goes to Yellow


Note: There are hidden segments as shown below i used wildcard "(\@)(*)(\^13)" to make them hidden

17994


sample file is attached too17995

is it possible to do that in VBA, Any hint or help would be appreciated. : pray2:: pray2:


Thanks in Advance

Cheers

Ethen

Ethen5155
01-11-2017, 06:24 AM
i tried my luck starting with this code, to export highlight text to a new excel file but i faced two problems


Sub ExportHighlightText()


Dim docCur As Document
Dim snt As Range
Dim Paragraphs As Range
Dim i As Integer

Dim appXL As excel.Application, xlWB As excel.Workbook, xlWS As excel.Worksheet
Dim path As XPath



Set appXL = CreateObject("Excel.Application")
appXL.Visible = True
Set xlWB = appXL.Workbooks.Add
Set xlWS = xlWB.Worksheets(1)




Application.ScreenUpdating = False

Set docCur = ActiveDocument


For Each snt In docCur.Sentences
If snt.HighlightColorIndex = wdBrightGreen Then
i = i + 1
xlWS.Cells(i, 1).Value = snt.Text
End If
Next snt


For Each snt In docCur.Sentences
If snt.HighlightColorIndex = wdYellow Then
i = i + 1
xlWS.Cells(i, 2).Value = snt.Text
End If
Next snt


ExitHandler:
Application.ScreenUpdating = True
Set snt = Nothing
Exit Sub



Resume ExitHandler
End Sub





first one it exports the text in column (B) but under other text in column (A) not opposite to it

17997


second issue that it exports text as sentences and divide it to two lines not as paragraphs



17998



and i'm still don't know how to get it back from excel to word with keeping same structure !! :think::think::doh:


Ethen

macropod
01-12-2017, 06:17 PM
Cross-posted (and answered) at: http://www.excelforum.com/showthread.php?t=1169352


Please read our policyon Cross-Posting in item 3 of the board rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3 (http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3)