Auto Export Excel Data to MS Word Form

preview_player
Показать описание
Easy way to populate MS word form using Excel table data.

main code :

Option Explicit
Const FilePath As String = "C:\Users\Acer-PC\Desktop\AUTOEXPORT\"
Dim wd As New Word.Application

Sub ExportButton()

Dim doc As Word.Document
wd.Visible = True

Dim Name As String
Dim Address As String

Name = ThisWorkbook.Sheets(1).Range("D5").Value 'value from sheet1
Address = ThisWorkbook.Sheets(1).Range("D6").Value

Copy2word "NameField", Name
Copy2word "AddressField", Address

doc.Close

wd.Quit
'MsgBox "Created files in " & FilePath & "!"

End Sub
Sub Copy2word(BookMarkName As String, Text2Type As String)
'copy each cell to relevant Word bookmark
wd.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName
wd.Selection.TypeText Text2Type
End Sub
Рекомендации по теме
Комментарии
Автор

This is SO HELPFUL!!! Thanks a million!!!!

lmcbunnylove
Автор

I am getting Error as "User-defined Type not defined" for "Dim wd As New Word.Application". Can i get it resolved?

guptabibek
Автор

Got an error in this part : Sub ExportButton() dunno why. it wasn't shown in the video. can you help me? Thanks

venndiagram
Автор

While creating new template old entry not getting remove pls suggest

ektathorat
Автор

Can we do this for bulk data like i have multiple input that I want to populate from Excel to word automatically.

hollywoodmovieclips
Автор

Sir I am getting run time error is
sorry we couldn't find your file.
Was it moved, renamed, or deleted?

gorisettyjhansi
Автор

This code is helpful, thanks a lot!! But, this code when you re-extract the data will add again, how we can improve by add code to clean data in word file before export data.

TuyetNguyen_
Автор

i would like to find out how to replace text in word document and save . the code should be run from excel

umrbekmatrasulov
Автор

i want to export the data based on selected rows only?how to do that?

MrMohanchem
Автор

where to find source code on link description?

XianandMarcus
Автор

Can you help eorr this Set doc = wd.Documents.Open(FilePath & "output.docx") file not found!!!

mengbunlong
Автор

Hello there.
I would like to ask you, how to save as document to different adress with naming of for instance by using cell value in excel

tomaskvetko
Автор

When I run the maco I get the message: Compile error. User-defined type not defined and the following line is gighlighted: Dim wd As New Word.Application

goldmaestro
Автор

I am trying this code in my sheet but it has found 462 error..can you check the below where i am wrong

Option Explicit
Const FilePath As String =
Dim wd As New Word.Application

Sub ExportButton()

Dim doc As Word.Document
wd.Visible = True

Dim Name As String
Dim Address As String
Dim District As String
Dim Mobile As String
Dim Email As String

Name = 'value from sheet1
Address =
District =
Mobile =
Email =

Set doc = wd.Documents.Open(FilePath & "output.docx")
Copy2word "NameField", Name
Copy2word "AddressField", Address
Copy2word "DistrictField", District
Copy2word "MobileField", Mobile
Copy2word "EmailField", Email

doc.Close

wd.Quit
'MsgBox "Created files in " & FilePath & "!"

End Sub
Sub Copy2word(BookMarkName As String, Text2Type As String)
'copy each cell to relevant Word bookmark
wd.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName
wd.Selection.TypeText Text2Type
End Sub

TRAVELLERBUZZ
Автор

How to copy the same formatting from excel to word? Please help. And thanks for your video.

SumanDevi-rxjd
Автор

I am getting an error 91 on this line below. Any thoughts on why?


wd.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName

brandonhill
Автор

Hello, can I use the online versions?
Like for onedrive?

rustyrobb_
Автор

@Code Ranger, thanks for detailed explanation. This code works perfectly but when I run the code second time, the data gets duplicate. I want to remove previous data before pasting new data. Any valuable suggestions how to do that?

Explorewithsingh
Автор

hello sir in this code we have a error like
" method and data member are not found"

gajendersingh
Автор

Thank you for your video. I am getting a compile error message: Named argument not found. its highlighting the following: Sub As String, Text2Type As String)

sherylm