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

  Рет қаралды 3,904

greggowaffles

greggowaffles

Жыл бұрын

Excel VBA Macro: Create Word Document & Add Table (Static Range). In this video, we go over how to add a table with a set range to a word document using excel. We also enable borders in the table and change the background color of the table with our code.
Code:
Sub add_table_2_word()
Dim objWord
Dim objDoc
Dim objSelection
Dim i As Integer
Dim j As Integer
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, 6, 3)
With CountryTable
With .Borders
.enable = True
.outsidecolor = RGB(0, 0, 0)
.insidecolor = RGB(0, 0, 0)
End With
.Rows(1).shading.backgroundpatterncolor = RGB(51, 204, 51)
For i = 1 To 6
For j = 1 To 3
.cell(i, j).Range.InsertAfter ThisWorkbook.Sheets("Sheet1").Cells(i, j).Text
Next j
Next i
End With
End Sub
#ExcelVBA #ExcelMacro

Пікірлер: 14
@MohAboAbdo
@MohAboAbdo Жыл бұрын
Thank you so much
@greggowaffles
@greggowaffles Жыл бұрын
No problem!
@Lyriks_
@Lyriks_ Жыл бұрын
Don't forget to close the word file once macro gets executed otherwise(for me at least) it causes a bug ! Good job Greggo
@greggowaffles
@greggowaffles Жыл бұрын
Thanks!
@alializadeh8195
@alializadeh8195 Жыл бұрын
مرسی
@greggowaffles
@greggowaffles Жыл бұрын
خواهش میکنم
@stanTrX
@stanTrX 7 ай бұрын
Thanks. Cant you get the _named_ table from excel and paste it to word?
@sallu21m
@sallu21m Жыл бұрын
Thanks for a educative lesson .... how can I get auto serial number in word table when I extract data from excelsheet ??
@johanmilterjakobsen1627
@johanmilterjakobsen1627 Жыл бұрын
Can you use the same method to make an Equation? If yes, then how can you do it?
@manoharbholankar1867
@manoharbholankar1867 Жыл бұрын
How can we add the table in specific place in a word template ?
@vikrampurohit3033
@vikrampurohit3033 Жыл бұрын
How to filter out with multiple criteria for a column, could you please explain me
@greggowaffles
@greggowaffles Жыл бұрын
Hope this helps! kzbin.info/www/bejne/rXLJoXxrfr-erM0
@vikrampurohit3033
@vikrampurohit3033 Жыл бұрын
@@greggowaffles thanks , I saw this video, the problem here is, I want to filter out with not criteria and need to delete all other rows and then need to paste it in a new sheet
@vikrampurohit3033
@vikrampurohit3033 Жыл бұрын
Can we connect for 5 mins please
Excel VBA Macro: Create Word Document & Add Table (Dynamic Range)
10:34
How To Work With Paragraphs In Word VBA
16:28
Sigma Coding
Рет қаралды 13 М.
When You Get Ran Over By A Car...
00:15
Jojo Sim
Рет қаралды 22 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 90 МЛН
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
How To Copy A Single Excel Table To Word Using VBA
25:07
Sigma Coding
Рет қаралды 10 М.
How To Copy Multiple Excel Ranges To Word Using VBA
21:10
Sigma Coding
Рет қаралды 4,9 М.
Free Excel VBA Course #35 - Creating Word Reports Using VBA
25:23
Wise Owl Answers - How do I resize a Word table after copying from Excel?
10:46
Add Rows to Word Table from UserForm in Word VBA
8:24
Learn Microsoft Office Programming
Рет қаралды 17 М.
How to get the Last Row in VBA(The Right Way!)
15:41
Excel Macro Mastery
Рет қаралды 152 М.
How to add a paragraph to a Word Document using Excel VBA
6:55
Keep On Learning with Sevilla
Рет қаралды 1,1 М.
Open Word Document from Excel VBA UserForm
12:14
Dr. Todd Grande
Рет қаралды 31 М.