Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-06-2016, 02:28 AM
thmsrox thmsrox is offline Creating a (shared!) file with CommandButton placing AutoText into the document Windows 7 64bit Creating a (shared!) file with CommandButton placing AutoText into the document Office 2013
Novice
Creating a (shared!) file with CommandButton placing AutoText into the document
 
Join Date: Jul 2016
Posts: 3
thmsrox is on a distinguished road
Default Creating a (shared!) file with CommandButton placing AutoText into the document

Hi,

I've been trying to create a document with CommandButtons that once clicked write the AutoText programmed into them. This works perfectly locally, but not externally.
The main issue is that I don't want other users to have to get a copy of my "Normal.dotm" file every time since it's too much of a hassle with the amount of AutoText used. The idea was to put just one copy of my Normal.dotm on a shared drive over the network and to have the code pull out that file so users would never have to swap around files on their PCs.

Something like this;



Quote:
Private Sub CommandButton21_Click()
'
' Bio Macro
'
'
Application.Templates( _
"S:\Thomas\Normal.dotm"). _
BuildingBlockEntries("Bio").Insert Where:=Selection.Range, RichText:=True
End Sub
This however does not work.
The original code does.

Quote:
Private Sub CommandButton21_Click()
'
' Bio Macro
'
'
Application.Templates( _
"C:\Users\Thomas\AppData\Roaming\Microsoft\Templat es\Normal.dotm"). _
BuildingBlockEntries("Bio").Insert Where:=Selection.Range, RichText:=True
End Sub
Ideas / help would be appreciated.
Reply With Quote
  #2  
Old 07-06-2016, 07:11 AM
gmayor's Avatar
gmayor gmayor is offline Creating a (shared!) file with CommandButton placing AutoText into the document Windows 10 Creating a (shared!) file with CommandButton placing AutoText into the document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Don't even think of sharing your normal template. It is a personal and single user file that is not intended to be shared.

Create a new template. Copy your macros and building blocks to it, save it as macro enabled then supply that template as an add-in. Include a ribbon to call your macros and make it even more useful.

The code to call a building block from that template would be

Code:
Application.Templates(ThisDocument.FullName).BuildingBlockEntries("Bio").Insert Where:=Selection.Range, RichText:=True
The attached should provide a clue.

Put it in the Word startup folder with Word closed - If you have not changed the preferred startup folder it can be located (in English language versions of Windows) by typing
%appdata%\Microsoft\Word\Startup
in the Windows Explorer Address bar and pressing Enter.
Attached Files
File Type: dotm MyBlocks.dotm (88.7 KB, 17 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 07-07-2016, 02:33 AM
thmsrox thmsrox is offline Creating a (shared!) file with CommandButton placing AutoText into the document Windows 7 64bit Creating a (shared!) file with CommandButton placing AutoText into the document Office 2013
Novice
Creating a (shared!) file with CommandButton placing AutoText into the document
 
Join Date: Jul 2016
Posts: 3
thmsrox is on a distinguished road
Default

Thanks for the help,

everything worked fine as you instructed, but only inside the template.
Once I load the template and use it as a document, when I click one of the CommandButtons it gives me the text-output from a different CB. After that no matter which other CB I attempt to click, nothing happens.

I have about 15 of these in the code behind the template.

Code:
Private Sub CommandButton210_Click()
    Application.Templates( _
        "V:\Folder\Filename.dotm" _
        ).BuildingBlockEntries("AutoTextName").Insert Where:=Selection.Range, _
        RichText:=True
End Sub
Works fine when I exit designermode in the template, works incorrect and broken when I load the template to make a standard document.
Reply With Quote
  #4  
Old 07-07-2016, 03:59 AM
gmayor's Avatar
gmayor gmayor is offline Creating a (shared!) file with CommandButton placing AutoText into the document Windows 10 Creating a (shared!) file with CommandButton placing AutoText into the document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The point is that with the approach I suggested (and demonstrated in the attachment) is that the template is used as an add-in. It is not intended to be used as a document. By using the add-in approach, the macros are available to all your documents.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 07-07-2016, 04:07 AM
thmsrox thmsrox is offline Creating a (shared!) file with CommandButton placing AutoText into the document Windows 7 64bit Creating a (shared!) file with CommandButton placing AutoText into the document Office 2013
Novice
Creating a (shared!) file with CommandButton placing AutoText into the document
 
Join Date: Jul 2016
Posts: 3
thmsrox is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
The point is that with the approach I suggested (and demonstrated in the attachment) is that the template is used as an add-in. It is not intended to be used as a document. By using the add-in approach, the macros are available to all your documents.
The main idea is that the users have a template with the macrobuttons already in place, so that they can keep re-using that same form. Once in place all that I would need to do in case of changes to the texts hidden behind the macro's is adjust those in the template that the users keep calling on. The plan is to have the users not use those macro's on their own documents, but just keep using the ones in that single document. Sorry if I didn't explain this thoroughly.
Reply With Quote
  #6  
Old 07-07-2016, 05:04 AM
gmayor's Avatar
gmayor gmayor is offline Creating a (shared!) file with CommandButton placing AutoText into the document Windows 10 Creating a (shared!) file with CommandButton placing AutoText into the document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

In that case use the example template as a document template instead of an add-in. Create new documents from it. The macro will work just the same in those documents.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoText List - Protected Document AJohn403 Word 3 04-20-2015 04:54 PM
Creating a (shared!) file with CommandButton placing AutoText into the document how to easily drop autotext into document Kendel Word 2 02-08-2015 09:50 AM
Creating a (shared!) file with CommandButton placing AutoText into the document I'm having trouble creating a Merge using label form and placing a shape in the text blockie Mail Merge 8 11-13-2013 11:28 PM
Creating a (shared!) file with CommandButton placing AutoText into the document Email Document via Commandbutton aqhibjaveed Word VBA 1 03-25-2013 11:22 PM
Creating a (shared!) file with CommandButton placing AutoText into the document Creating a shared template with selections gmsp26 Word 1 04-14-2011 05:18 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft