Transferring Excel Array to Word table

JoeS01

Well-known Member
Joined
Jun 25, 2005
Messages
832
Has anyone had any success in transferring a single dimensional array ( in Excel) to a specific column in Word?
 
As far as getting to any point in the table, you do it the same way as you work with a Range object in Excel.

Code:
tbl.Cells(1, 1).Select

For your next question - and it looks like you were already doing this? - if you have an array that is the same size and same position as your previous array, you should populate the Word table in the same loop. I will use your previously-posted code to illustrate this.

What's wrong with what you already had:

Code:
   For I = LBound(DocNo) To UBound(DocNo)
       .Tables(4).Columns(1).Cells(I - LBound(DocNo) + 2).Select
      wrdApp.Selection.TypeText (DocNo(I))
 
      .Tables(4).Columns(2).Cells(I - LBound(DocNo) + 2).Select
      wrdApp.Selection.TypeText (VerNo(I))
 
      .Tables(4).Columns(3).Cells(I - LBound(DocNo) + 2).Select
      wrdApp.Selection.TypeText (DrgTitle(I))
    Next I


Or, instead of using the Columns collection, just using the Cell collection:

Code:
    For I = LBound(DocNo) To UBound(DocNo)
     .Tables(4).Cell(I - LBound(DocNo) + 2, 1).Select
      wrdApp.Selection.TypeText (DocNo(I))
 
      .Tables(4).Cell(I - LBound(DocNo) + 2, 2).Select
      wrdApp.Selection.TypeText (VerNo(I))
 
      .Tables(4).Cell(I - LBound(DocNo) + 2, 3).Select
      wrdApp.Selection.TypeText (DrgTitle(I))
    Next I

If you had determined the column number programmatically, you just +1 to the previous column number, +2 for the next column number, etc.


Overall, there seems to be an issue you're having of determining the table (which we've solved) but also the column of that table, into which the data needs to go. If you explain that situation more clearly, it should be easier for us to come up with a solution.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Thanks for taking the time to post this, iliace, very much appreciated.

In terms getting back to the first cell in the table, I tried this before I recieved your post, and it generated an error - did not support this method

Obviously, your method is simpler and quicker, but I am wondering why the following did not work.

Code:
  'go to start of document Table where bookmark is located
    If wrdDoc.Bookmarks.Exists("TABLE_START") = True Then
 
        Selection.Goto What:=wdGoToBookmark, Name:="TABLE_START"   <<<ERROR< p> ERROR     
 
    Else
       MsgBox " no bookmark found at start of Table"
 
    End If


With regards to what I am trying to do, I just want to use one bookmark that users can specify where the data is to go in a table, and then three columns of data are installed starting at the bookmarked cell in the top LH corner.
 
Last edited:
Upvote 0
I created a table, and made a bookmark within it using the name TABLE_START. Using the same code, I cannot recreate the bookmarks problem - it works as expected. What error are you getting, and on which line?
 
Upvote 0
Error #438 "Object doesn't support this property or method" on the line in red below. I have checked that the bookmark actually does exist.

Code:
'go to start of document Table
    '.Tables(TableNo).Columns(1).Cells(1).Select
 
    If wrdDoc.Bookmarks.Exists("TABLE_START") = True Then
        [COLOR=red][B]Selection.Goto What:=wdGoToBookmark, Name:="TABLE_START"[/B][/COLOR]
    Else
       MsgBox " no bookmark found at start of Table"
    End If

Perhaps it has something to do with the code being an Excel macro, not a Word VBA macro?

The term " Selection" is out of the blue - I don't recall selecting anything
 
Last edited:
Upvote 0
Oh, it's probably thinking you want the Excel selection. Specify the Word application object. For example:

Code:
wrdApp.Selection.Goto

Sorry I didn't even think of that previously - I was running the code directly in Word.
 
Upvote 0

Forum statistics

Threads
1,216,474
Messages
6,130,841
Members
449,598
Latest member
sunny_ksy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top