Excel Userform VBA

Hi I am trying to take data from the Excel userform and with the help of button click put it on
word template, is that possible with the excel userform
surah79Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arno KosterCommented:
Sure, you can use this code to start word, open a file, and insert some data
    Set wrd = CreateObject("Word.application")
    wrd.Visible = True
    Set doc = wrd.documents.Open("[path][template file]")
    Set sel = wrd.Selection
    sel.typeparagraph
    sel.typetext Range("A1").Text

Open in new window

0
surah79Author Commented:
Hi I have like 8 Text box in my Userform and want them to go in the word document .
0
surah79Author Commented:
Hi  

Gving me an compliter error as wrd not defined
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

surah79Author Commented:
HI guys

I can open word template now but i want to transfer the data from Excel userform to that word template any help will be helpful

Dim wrd As Object
Dim doc As Object
Dim sel As Object

 Set wrd = CreateObject("Word.Application")
 On Error Resume Next
Err.Clear
    wrd.Visible = True
    Set doc = wrd.documents.Open("H:\UserSettings\Desktop\Tnew.doc")
    Set sel = wrd.Selection
    sel.typeparagraph
    sel.typetext Range("A1").Text
0
Arno KosterCommented:
When you want to transfer the data from a userform, make sure that the code is placed inside the userform code page.

You can then use

sel.typetext Textbox1.text

instead of

sel.typetext range("a1").text
0
surah79Author Commented:
If I had to transfer the information to particular field on the word template from the Excel userform. How can I do that
0
Arno KosterCommented:

That would require you to locate the field on the word template, selecting the field and inserting the data.
Is it possible for you to post a sample template ?
That way i can mroe easily supply you with a working approach
0
surah79Author Commented:
 I need to transfer the information in word template from the excel userform and is it possible the excel userform can be multiple users ,like multiple user can input the data in it.
TEST.doc
0
Arno KosterCommented:
you can use this code :
Sub process()
Dim wrd As Object
Dim doc As Object
Dim sel As Object

Const wdReplaceAll = 2

    Set wrd = CreateObject("Word.Application")
 
    wrd.Visible = True
    Set doc = wrd.documents.Open("H:\UserSettings\Desktop\Tnew.doc")
    Set sel = wrd.Selection
    
    With sel.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "<<CITY>>"
        .Replacement.Text = Range("B1")
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With

End Sub

Open in new window

0
Arno KosterCommented:
please note that because of the Range("B1") replacement, this code should be placed in a worksheet code section.

otherwise, use


.Replacement.Text = Worksheets("Sheet1").Range("B1")

instead
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
surah79Author Commented:
thanks a lot
0
Arno KosterCommented:
you're welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.