Excel VBA Macro: Create Word Document & Add Table (Dynamic Range)

  Рет қаралды 4,995

greggowaffles

greggowaffles

Күн бұрын

Excel VBA Macro: Create Word Document & Add Table (Dynamic Range). In this video, we go over how to add a table to a word document with a dynamic range from excel. We also briefly review enabling borders in the table and changing the background color of the table with our code. We finally change the size of the range to show that the macro will include all rows and columns regardless of the size of the range coming from excel.
Code:
Sub add_table_2_word_dynamic_range()
Dim objWord
Dim objDoc
Dim objSelection
Dim i As Integer
Dim j As Integer
Dim ws As Worksheet
Dim row_count As Integer
Dim col_count As Integer
Set ws = ThisWorkbook.Sheets("Sheet1")
ws.Activate
row_count = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))
col_count = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlToRight)))
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
Set objSelection = objWord.Selection
objWord.Visible = True
objWord.Activate
Set CountryTable = objDoc.Tables.Add(objSelection.Range, row_count, col_count)
With CountryTable
With .Borders
.enable = True
.outsidecolor = RGB(0, 0, 0)
.insidecolor = RGB(0, 0, 0)
End With
.Rows(1).shading.backgroundpatterncolor = RGB(0, 153, 255)
For i = 1 To row_count
For j = 1 To col_count
.cell(i, j).Range.InsertAfter ws.Cells(i, j).Text
Next j
Next i
End With
End Sub
#ExcelVBA #ExcelMacro

Пікірлер: 10
@josephwilson6908
@josephwilson6908 Жыл бұрын
This is awesome, exactly what I was hunting for... Cheers! 👍
@greggowaffles
@greggowaffles Жыл бұрын
Awesome! Glad to hear that!!
@kpcrompton
@kpcrompton Ай бұрын
Thank you for the easy to follow tuition. Is it possible for the source data to start a cell other than "A1" and then the range start from there? Thanks again.
@MohAboAbdo
@MohAboAbdo Жыл бұрын
Thank you so much
@greggowaffles
@greggowaffles Жыл бұрын
You’re very welcome
@salimkoc4254
@salimkoc4254 Жыл бұрын
Hello, how can i do Excel VBA to Export Range as Image ? Can you help me please.
@user-rj5ng1zo2f
@user-rj5ng1zo2f Жыл бұрын
This is very useful, thank you! I have a question, what if the columns in each row of the table could be different, some row contains merged cell? Would like to know some contents on this 😊
@carlinecharles9190
@carlinecharles9190 9 ай бұрын
Hi, Can you code that in Word alone? I am interested in learning coding. Where should I start? This was great.
@kingsantiago1221
@kingsantiago1221 10 ай бұрын
hi sir. how about creating tables based on the column value. meaning it would create a different table each time the macro see a value on a specific column example. Column A is for Test Case#, so for row 1 its test case 1, the next rows are the steps where it the column A is blank, then once the macro sees a value for Column A like Test Case 2, it would create another table on the next page of the word. HELP ME PLSS
@LoLDDRRNob
@LoLDDRRNob Жыл бұрын
How to insert text after the table ??
50 things you didn't know Excel can DO 💡
30:03
Chandoo
Рет қаралды 270 М.
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 43 МЛН
Playing hide and seek with my dog 🐶
00:25
Zach King
Рет қаралды 34 МЛН
Best Toilet Gadgets and #Hacks you must try!!💩💩
00:49
Poly Holy Yow
Рет қаралды 19 МЛН
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 17 МЛН
Macro to extract data from Word table to Excel | Excel VBA
12:49
Extreme Automation - Kamal Girdher
Рет қаралды 39 М.
VBA Macro Code - Copy Data from Multiple Word Files to Excel
10:22
Learn Excel VBA
Рет қаралды 12 М.
Excel VBA Macro: Add Gridlines/Borders To A Table (Dynamic Range)
4:28
Excel Macro to create PDF files using Word template
7:29
Extreme Automation - Kamal Girdher
Рет қаралды 13 М.
#WORDVBA   WORD VBA - Insert tables
11:35
Computeraidedautomation.com
Рет қаралды 3,2 М.
Excel VBA Macro: Paste Range (Table) As Image In Email Body
9:35
greggowaffles
Рет қаралды 34 М.
Automate Word Document from Excel Using VBA
7:45
Nodes Automations
Рет қаралды 51 М.
Free Excel VBA Course #35 - Creating Word Reports Using VBA
25:23
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 43 МЛН