Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-31-2017, 08:56 AM
modiria50989 modiria50989 is offline replacing multiple ranges in excel with tables in word from top to bottom Windows 8 replacing multiple ranges in excel with tables in word from top to bottom Office 2010 64bit
Banned
replacing multiple ranges in excel with tables in word from top to bottom
 
Join Date: Aug 2017
Posts: 7
modiria50989 is on a distinguished road
Default replacing multiple ranges in excel with tables in word from top to bottom

I have a code that pastes word tables from a word file into the sheet1 in Excel. Then I go to the sheet1 and without changing header names and data's location, I revise the original data to new data. Now, here is my question: how to return those revised data back to the Word document. In other words I want to see all tables into the word file with updated information.

My question in different way:
If you have a word document with a few tables in it, then if you go to Excel and run the bellow code from Excel VBA module? You will see how a browser opens to select a word file, then each table will pasted from row 1 and it goes all the way down and there would be 1 empty row between each table-range data. So i can revise all values I want.
Now my question is: how to replace word tables with those individual ranges (table ranges) in excel?
Note that in the excel we can recognize boundaries of each table since there is a empty row between them.
Please let me know if you need more explanation.



Just in case: my word file includes a lot of lines, paragraphs, and a few tables.

Here is my code that I paste word-tables into the excel sheet (how to return it back?):

Code:
Option Explicit
Sub ImportWordTable()
Dim wdDoc AsObject
Dim wdFileName AsVariant
Dim tableNo AsInteger'table number in Word
Dim iRow AsLong'row index in Excel
Dim iCol AsInteger'column index in Excel
Dim resultRow AsLong
Dim tableStart AsInteger
Dim tableTot AsInteger
OnErrorResumeNext
ActiveSheet.Range("A:AZ").ClearContents
wdFileName = Application.GetOpenFilename("Word files (*.doc),*.doc", , _
"Browse for file containing table to be imported")
If wdFileName = FalseThenExitSub'(user cancelled import file browser)
Set wdDoc = GetObject(wdFileName) 'open Word file
With wdDoc
tableNo = wdDoc.tables.Count
tableTot = wdDoc.tables.Count
If tableNo = 0Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
ElseIf tableNo > 1Then
tableNo = InputBox("This Word document contains " & tableNo & " tables." & vbCrLf & _
"Enter the table to start from", "Import Word Table", "1")
EndIf
resultRow = 1
For tableStart = 1To tableTot
With .tables(tableStart)
'copy cell contents from Word table cells to Excel cells
For iRow = 1To .Rows.Count
For iCol = 1To .Columns.Count
Cells(resultRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
Next iCol
resultRow = resultRow + 1
Next iRow
EndWith
resultRow = resultRow + 1
Next tableStart
EndWith
EndSub

Last edited by modiria50989; 08-31-2017 at 04:06 PM.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
replacing multiple ranges in excel with tables in word from top to bottom Take String of numbers, expand ranges, sort, then compress back into ranges AustinBrister Word VBA 19 08-22-2016 05:18 PM
replacing multiple ranges in excel with tables in word from top to bottom Creating multiple tables VBA from Excel to Word francesco Word VBA 1 01-07-2016 04:08 AM
replacing multiple ranges in excel with tables in word from top to bottom using if and compare with multiple criteria and ranges of values bill3kradio Mail Merge 7 11-17-2014 01:06 PM
replacing multiple ranges in excel with tables in word from top to bottom Replacing multiple words at once in excel document Legaly Excel 2 05-23-2014 08:30 AM
replacing multiple ranges in excel with tables in word from top to bottom Copying Multiple tables from excel into a single word document dineshtgs Word Tables 1 04-07-2011 01:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:26 PM.


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