[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Excel Userform VBA

Posted on 2011-10-21
12
Medium Priority
?
351 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:surah79
  • 6
  • 6
12 Comments
 
LVL 19

Expert Comment

by:Arno Koster
ID: 37006233
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
 

Author Comment

by:surah79
ID: 37016161
Hi I have like 8 Text box in my Userform and want them to go in the word document .
0
 

Author Comment

by:surah79
ID: 37016217
Hi  

Gving me an compliter error as wrd not defined
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:surah79
ID: 37016241
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
 
LVL 19

Expert Comment

by:Arno Koster
ID: 37016393
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
 

Author Comment

by:surah79
ID: 37021744
If I had to transfer the information to particular field on the word template from the Excel userform. How can I do that
0
 
LVL 19

Expert Comment

by:Arno Koster
ID: 37022976

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
 

Author Comment

by:surah79
ID: 37024185
 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
 
LVL 19

Expert Comment

by:Arno Koster
ID: 37025103
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
 
LVL 19

Accepted Solution

by:
Arno Koster earned 2000 total points
ID: 37025119
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
 

Author Closing Comment

by:surah79
ID: 37029102
thanks a lot
0
 
LVL 19

Expert Comment

by:Arno Koster
ID: 37029798
you're welcome
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question