Question:
Excel VBA to create a table in Word?
kwambonambi
2012-02-14 03:09:31 UTC
Hi Everybody,

I am currently rather clueless with Excel VBA and have been trying to create a table in Word 2007 using Excel 2007 VBA. In essence what I would like to have is a button in Excel that reads "Create table" and when clicked a word document opens and contains a table with 8 rows and 4 columns.

I have looked at a number of online examples but seem to be going in circles. Any clues (or answers) with the code?

Thank you for your assistance.
Three answers:
garbo7441
2012-02-14 10:27:41 UTC
You seem to have mixed your syntax for Range and Cells. The Cells method identifies the cell by the row and column reference (R1C1 reference style). For example, cell A1 would be referred to as:



Cells(1,1)



The Range method refers to cells by the A1 reference style:



Range("A1")



I would suggest you change:



wrdRange = Sheet1.Cells("A40:D47")



to



wrdRange = Sheet1.Range("A40:D467")
catledge
2016-11-18 03:49:45 UTC
Vba Create Table
nicefx
2012-02-14 03:41:10 UTC
you can do like in this site : http://www.mrexcel.com/forum/showthread.php?t=329801



but before you write the VBA code, do add reference to Word Library, here's how :

1) Open VBE

2) Choose Tools in menubar

3) Choose Reference...

4) Find and check : Microsoft Word 14.0 Library

5) Ok


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...