Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2022, 06:36 PM
Peterson Peterson is offline Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 143
Peterson is on a distinguished road
Default

It's unclear to me whether your users are saving a copy of the template to the same folder in which they save a copy of the file? In other words, for every file they make, they also make a copy of the template??



My understanding is that DOCM files cannot contain building blocks; only templates can. Unless I'm wrong, what I would do is modify your macros per the code below:

Code:
Sub CustomizeLocalFilepathsToUsername() ' 03/18/2022

    ' Create a variable for the filepath to your template:
    Dim strFilepath As String
    
    ' Use the Environ("UserProfile") function to get the first portion of the
    ' user's file path -- that is, C:\User\username -- and concatenate with the
    ' rest of the path to your template in the STARTUP folder:
    strFilepath = Environ("UserProfile") & _
    "\AppData\Roaming\Microsoft\Word\STARTUP\IT GATu 2.dotm"
    
    ' Here's what the full string looks like:
    Debug.Print strFilepath
    
    ' You need to run this line to access your template's building blocks:
    Application.Templates.LoadBuildingBlocks
    
    ' Modify the building-block paths in your template by replacing the hard-
    ' coded paths to the template with the "strFilepath" variable:
    Application.Templates(strFilepath).BuildingBlockEntries("HOME AND EXPOSURE").Insert _
    Where:=Selection.Range, RichText:=True
End Sub
Next, have your users save a copy of the template -- that is, the DOTX file -- to their Startup folder:
C:\Users\%username%\AppData\Roaming\Microsoft\Word \STARTUP
Note that your users won't be able to create new documents based on this template if you put it here. If they need to do that, then it'd be better to store the template in their default templates location, which, unless they've changed the default location, is here:
C:\Users\%username%\AppData\Roaming\Microsoft\Temp lates
If you're going to have your users store the template here, modify the code above with this path, not the STARTUP path...
Reply With Quote
  #2  
Old 03-19-2022, 05:47 AM
gorkac gorkac is offline Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Banned
Content blocks stop working when changing file path
 
Join Date: Jul 2021
Location: Usa
Posts: 62
gorkac is on a distinguished road
Default

Thanks in advanced.
STEP 1:
Captura1.png
This file cannot be removed, it is just to copy and paste to the new path.


Content blocks in this file:
Code:
Application.Templates( _
"L:\06. MODELOS DE DOCUMENTOS\01 ATESTADOS\ACCIDENTES DE CIRCULACIÓN\BAEI\Informe Tecnico\BAEI - INFORME TÉCNICO.dotm"). _
BuildingBlockEntries("INICIO Y EXPOSICION DE HECHOS").Insert Where:=Selection.Range, RichText _
:=True
STEP 2:

New location:
L:\02.- ATESTADOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\unknown variable folder name\BAEI – INFORME TECNICO.docm
Captura7.PNG

STEP 3:
Ask the user for the name of that new folder.

Captura5.PNG

Worker copy and paste to that new location the file:
L:\02.- ATESTADOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-14367894\BAEI – INFORME TECNICO.docm

Captura6.PNG

STEP 4:

THIS IS WHAT I NEED:

Code that replaces the content block path of the original file with the new path
to do this in the file that the worker has taken to its new location:
REPLACES:
Code:
Application.Templates( _
"L:\06. MODELOS DE DOCUMENTOS\01 ATESTADOS\ACCIDENTES DE CIRCULACIÓN\BAEI\Informe Tecnico\BAEI - INFORME TÉCNICO.dotm"). _
BuildingBlockEntries("INICIO Y EXPOSICION DE HECHOS").Insert Where:=Selection.Range, RichText _
:=True
BY:

Code:
Application.Templates( _
" L:\02.- ATESTADOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-14367894\BAEI – INFORME TECNICO.docm"). _
BuildingBlockEntries("INICIO Y EXPOSICION DE HECHOS").Insert Where:=Selection.Range, RichText _
:=True
This way the contentblocks would work regardless of the route that the user saves.

Can be done?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mapped Content Controls in Building Blocks? Charles Kenyon Word 6 05-21-2021 05:40 PM
Stop hyperlink to a file from changing address - causes problems with pdf c.davidson Word 1 09-15-2020 11:11 PM
Content blocks stop working when changing file path New building blocks have stopped working (Word 2016) Genericname1111 Word 0 05-20-2020 04:17 PM
Content blocks stop working when changing file path Get image path from content control field - NO VBA possible thoerzer Word 5 10-10-2019 12:10 AM
Changing Absolute path to Relative in a Macro MrKim Excel Programming 13 01-26-2019 02:18 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:17 AM.


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