Solved

Word VBA, add autotext with data from the userform only if checked

Posted on 2014-07-31
6
1,118 Views
Last Modified: 2014-08-01
Hi guys,

I'm still novice with VBA so still learning, im trying to get my head around a functionallity that should be able to insert a Specific autotext (a table with some placeholders, which are embedded in the document already). and insert the text which you have entered in the userform, but only if its checked.

So in short.
* Tick a checkbox in the userform to true
* It will insert an Autotext, which is a placeholder at a bookmark - the placeholder itself has other bookmarks which needs to retrieve data from the userform.

I'm sorry if the explanation is a bit confusing, but i have attached a document with what i got so far... you might get a better insight of what i'm trying to do :)

testdoc.dotm.jpg - Please rename the file to "testdoc.dotm", the *.dotm file extention was not allowed to be uploaded

Thank you in advance
0
Comment
Question by:Hakum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40231412
I think that you need something like this:
Private Sub CommandButton1_Click()
    If CheckBox1.Value = True Then
        My Template.BuildingBlockEntries("MyAutoText").Insert, _
             Where:=MyDocument.Bookmarks("MyBookMark1").Range, RichText:=True
        MyDocument.Bookmarks("MyBookMark2").Range.Text = TextBox1.Text
    End If
End Sub

Open in new window

I am having trouble with your file. My browser tries to display it.
That is because you embedded it into the question after uploading it.
0
 
LVL 1

Author Comment

by:Hakum
ID: 40231473
try to right click on it and save it as link and rename it to "testdoc.dotm"
0
 
LVL 1

Author Comment

by:Hakum
ID: 40231488
i tried the code but its not working :S

please try to view the document and you might get a better idea of what i'm thinking

thank you in advance for you time :)
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 1

Author Comment

by:Hakum
ID: 40231522
I guess this is a alternative

Capture.PNG
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40232022
You would need to change the code so that the names of the Autotext, Bookmarks, Userform controls and template fit your situation. I notice that you have put the Autotext in the template, so this code shows how to find the template for the active document.
Private Sub cmdOK_Click()
Dim tmpl As Template
If Me.CheckBox1.Value = True Then
    Set tmpl = ActiveDocument.AttachedTemplate
       tmpl.BuildingBlockEntries("Placeholder1").Insert _
       ActiveDocument.Bookmarks("Placeholder1").Range, True
        ActiveDocument.Bookmarks("Text1").Range.Text = Me.txttext1.Text
End If
MsgBox "Document pushed ok"

End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:Hakum
ID: 40233641
Works like a charm!!!! thank you soo much for your time :)
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

617 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