Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-22-2017, 05:46 PM
emblackett emblackett is offline Windows 10 Office 2016
Novice
 
Join Date: Sep 2017
Posts: 2
emblackett is on a distinguished road
Default Recording code to create Autotext entries

Hi,


I tried to record a macro in Word 2016 to create autotext entries. I recorded the following steps:
1. Click Insert tab
2. Select Quick Parts / Autotext
3. Type a name for the entry
4. Click OK

When I looked in the code window nothing had been recorded, only the name of the macro at the beginning Sub macro1() and then Sub End. Can anyone explain why no code would be recorded, the document was saved as a Word macro enabled template

I repeated the recording using ALT+ F3 instead of ribbon clicks, to bring up the dialog box, and entered the autotext name. This code (below) was recorded and the autotext entry was made.

Sub Macro3()
'
' Macro3 Macro
'
'
ActiveDocument.AttachedTemplate.BuildingBlockEntri es.Add Name:="WEL", _
Range:=Selection.Range
End Sub

I then deleted the new entry from autotext and tested the macro, but it goes into debug. Can anyone help?

Thanks
Liz
Reply With Quote
  #2  
Old 09-22-2017, 07:03 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,319
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

There are many things macro won't record, including most Ribbon actions. In any event, when creating code, the macro recorder is about as smart as a box of rocks.

The code you've posted as Macro3 is missing some required BuildingBlockEntries.Add parameters. The required parameters are:
• Name
• Type
• Category
• Range
The macro recorder should have recorded all of the required parameters, but evidently it doesn't.

For your purposes you'd need something like:
Code:
Sub Demo()
ActiveDocument.AttachedTemplate.BuildingBlockEntries.Add _
  Name:="WEL", Type:=wdTypeAutoText, Category:="General", Range:=Selection.Range
End Sub
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 09-25-2017, 02:00 AM
emblackett emblackett is offline Windows 10 Office 2016
Novice
 
Join Date: Sep 2017
Posts: 2
emblackett is on a distinguished road
Default Autotext entries

Many Thanks that works well.

Cheers
Reply With Quote
Reply

Tags
word vba macro
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making AutoText entries available to the Outlook email editor Jennifer Murphy Word 8 01-03-2017 03:51 PM
alphabetize a list (manual index) with entries and sub-entries shmu Word 5 08-01-2016 11:15 PM
UserForm of Autotext Entries ptmuldoon Word VBA 11 02-13-2016 09:36 AM
Using Word autocorrect and autotext entries in outlook dswapp Outlook 2 11-24-2010 10:18 AM
Maintaining AUtotext Entries from an external table. kelzud Word Tables 0 07-28-2009 01:31 PM


All times are GMT -7. The time now is 09:32 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft