Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-17-2022, 05:51 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 Content blocks stop working when changing file path

Good morning. I have a docm template with vba code inside. This code has dozens of lines that refer to blocks of content that I have been creating in this style:
Code:
Application.Templates( _
            "C:\Users\X041754\Desktop\IT GATu.dotm"). _
            BuildingBlockEntries("IT VEH LIGERO").Insert Where:=Selection.Range, RichText _
            :=True
The problem occurs when the user using this template saves their work in another path, when they open their copy from that path, the code no longer finds these content blocks.
Please help.


I don't know how to implement a code so that, even if the location changes, I will be able to continue using the macros and the code.
Reply With Quote
  #2  
Old 03-17-2022, 02:39 PM
Charles Kenyon Charles Kenyon is online now Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,474
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

See Using VBA to Insent an AutoText Entry or other Building Block.
Have your macro and the building block in the same template and use the fullname of ThisDocument as your source location.
Reply With Quote
  #3  
Old 03-18-2022, 12:43 PM
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

Quote:
Originally Posted by Charles Kenyon View Post
See Using VBA to Insent an AutoText Entry or other Building Block.
Have your macro and the building block in the same template and use the fullname of ThisDocument as your source location.
I didn't explain myself well, sorry.
I have the template in
Code:
Application.Templates( _
            "C:\Users\gorka\Desktop\IT GATu 2.dotm"). _
            BuildingBlockEntries("HOME AND EXPOSURE").Insert Where:=Selection.Range, RichText _
            :=True
If I work from that directory, the macros work. But my co-workers have to save a .docm copy in the path L:\02.- Reports 2022\File"folder with random number"\IT GATu 2.dotm
If they try to rework the document from that new location, the building blocks no longer work.
Note: folder with random number are folders that they must name as a long number. For example: L:\02.- Reports 2022\File\1725849\IT GATu 2.dotm

Last edited by gorkac; 03-18-2022 at 12:45 PM. Reason: One more question.
Reply With Quote
  #4  
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
  #5  
Old 03-19-2022, 03:33 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

Quote:
Originally Posted by Charles Kenyon View Post
See Using VBA to Insent an AutoText Entry or other Building Block.
Have your macro and the building block in the same template and use the fullname of ThisDocument as your source location.
how do I do that?
Reply With Quote
  #6  
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
  #7  
Old 03-19-2022, 11:29 AM
Charles Kenyon Charles Kenyon is online now Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,474
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
See Using VBA to Insent an AutoText Entry or other Building Block.
Have your macro and the building block in the same template and use the fullname of ThisDocument as your source location.
Quote:
Originally Posted by gorkac View Post
how do I do that?
Save both the building block and the macro in the same template. You can decide where to save both of these as you create them or move them later. Where can Building Blocks be stored? Organizing your macros by Beth Melton, Word MVP

In that situation, the location of your building block for your code will be in the template:
Code:
ThisDocument.Fullname
ThisDocument always refers to the name of the document that holds the macro. Fullname gives both the name and path automatically.

If the building block is used in multiple templates, it should be in a loaded global template and have a unique name. In that case, look at the macro for situation 3 on my linked page.
Reply With Quote
  #8  
Old 03-19-2022, 12:56 PM
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

I do not understand well. I expected it to tell me something like: replace the part L:\06. MODELOS DE DOCUMENTOS\01 ATESTADOS\ACCIDENTES DE CIRCULACIÓN\BAEI\Informe Tecnico\BAEI - INFORME TÉCNICO.dotm for the variable "givemepath" or something like that
Reply With Quote
  #9  
Old 03-19-2022, 01:39 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 difficult to determine your process because your screenshots appear to omit files that are also in the folder. And the folder path is including a file that is NOT appearing.

For example, you have a screenshot (Step 2) with a full filepath that includes a document, but that document is not shown in the list of files.

Below, the path includes a FILE -- BAEI - INFORME TECNICO.docm -- but that file doesn't appear in the list of files.

Code:
L:\02.- ATESTATDOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-17851411703\BAEI - INFORME TECNICO.docm
If you can confirm that the following steps are EXACTLY the process your users are taking, then it would be possible to help figure out the solution:
1. User goes to the following folder (or maybe other folders, too) with templates and makes a COPY of a template -- to be absolutely clear -- a DOTX file:
Code:
L:\06. MODELOS DE DOCUMENTOS\01 ATESTADOS\ACCIDENTES DE CIRCULACION\Informe Tecnico\
2. User creates a new folder with numerical name, for example, AT-123456789.
3. User PASTES the template (DOTX) file into the new folder.
4. User creates a new DOCM document file based on the template.
The folder now CONTAINS BOTH THE *TEMPLATE* (DOTX) AND THE *FILE* (DOCM).
5. The user now works on the DOCM file.
Again, if this is EXACTLY the process your users are using, then the problem can be solved.

As an aside, and assuming this is, in fact, the process, unless there is some special business reason for including both the template (DOTX) file AND the document (DOCM) file in the same folder, this is a highly unusual work flow. It would be vastly simpler to store the templates in your users' default template folder, as noted in my earlier post.

Finally, my earlier direction to save the template in the STARTUP folder is probably impractical because your users apparently have to create new files based on the templates, which cannot be done with templates in the STARTUP folder.
Reply With Quote
  #10  
Old 03-20-2022, 04:54 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

For example, you have a screenshot (Step 2) with a full filepath that includes a document, but that document is not shown in the list of files.
"because the file is inside each folder AT-12345678, AT-8659320,etc, it is so that you can see how it is structured"
"L:\02.- ATESTADOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-1234568\BAEI – INFORME TECNICO.docm
L:\02.- ATESTADOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-8659320\BAEI – INFORME TECNICO.docm
L:\02.- ATESTADOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-4236793\BAEI – INFORME TECNICO.docm"

Below, the path includes a FILE -- BAEI - INFORME TECNICO.docm -- but that file doesn't appear in the list of files.
"because the file is inside each folder, it is so that you can see how it is structured"

Code:
L:\02.- ATESTATDOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-17851411703\BAEI - INFORME TECNICO.docm
If you can confirm that the following steps are EXACTLY the process your users are taking, then it would be possible to help figure out the solution:
1. User goes to the following folder (or maybe other folders, too) with templates and makes a COPY of a template -- to be absolutely clear -- a DOTX file (a DOTM file it works):
Code:
L:\06. MODELOS DE DOCUMENTOS\01 ATESTADOS\ACCIDENTES DE CIRCULACION\Informe Tecnico\
2. User creates a new folder with numerical name, for example, AT-123456789. [B]YES[B]
3. User PASTES the template (DOTX) file into the new folder. [B]YES[B]
4. User creates a new DOCM document file based on the template.
The folder now CONTAINS BOTH THE *TEMPLATE* (DOTX) AND THE *FILE* (DOCM).
NOT, ONLY TEMPLATE DOCM 5. The user now works on the DOCM file.
Again, if this is EXACTLY the process your users are using, then the problem can be solved.

1.- Which is quite simple to understand. Workers have a template (BAEI - INFORME TECNICO.docm).

2.- They copy it (so as not to overwrite it and so the next partner can use it) and paste it into the path:
L:\02.- ATESTATDOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\

3.- A folder is created, to differentiate it from other folders that other colleagues create, for example: AT-12345678

4.-So you are left with the following path: L:\02.- ATESTATDOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-17851411703\BAEI - INFORME.docm TECNICO.docm

Then comes the problem that I explain
As the file BAEI - INFORME TECNICO.docm contains contentblock of this style:

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
in the new path
Code:
L:\02.- ATESTATDOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-17851411703\BAEI - INFORME TECNICO.docm
it does not work.

I need a way to ask the worker what address is the new path where the BAEI template is going to work - INFORME TECNICO.docm and thus this route replaces the one that comes in the content blocks so that they work.
Reply With Quote
  #11  
Old 03-20-2022, 12:55 PM
Charles Kenyon Charles Kenyon is online now Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,474
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Cross-Posted at vba - Building block does not work if someone changes the location template - Stack Overflow.
For cross-posting etiquette, please read: A Message to Forum Cross-Posters
Reply With Quote
  #12  
Old 03-20-2022, 01:17 PM
Charles Kenyon Charles Kenyon is online now Content blocks stop working when changing file path Windows 10 Content blocks stop working when changing file path Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,474
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by gorkac View Post
Then comes the problem that I explain
As the file BAEI - INFORME TECNICO.docm contains contentblock of this style:

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
in the new path
Code:
L:\02.- ATESTATDOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION\AT-17851411703\BAEI - INFORME TECNICO.docm
it does not work.

I need a way to ask the worker what address is the new path where the BAEI template is going to work - INFORME TECNICO.docm and thus this route replaces the one that comes in the content blocks so that they work.
A .docm file is not a Word template. It cannot hold a building block.



If you give your users a .dotm template, it can hold the building block. Is there some reason to have the building block in a separate file?
Reply With Quote
  #13  
Old 03-20-2022, 10:55 PM
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

Quote:
Originally Posted by Charles Kenyon View Post
A .docm file is not a Word template. It cannot hold a building block.



If you give your users a .dotm template, it can hold the building block. Is there some reason to have the building block in a separate file?
I can't upload the file because it is 10MB
Reply With Quote
  #14  
Old 03-20-2022, 10:59 PM
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

Sorry, it's a .dotm template, actually.
Reply With Quote
  #15  
Old 03-20-2022, 11:13 PM
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

Quote:
Originally Posted by Charles Kenyon View Post
A .docm file is not a Word template. It cannot hold a building block.



If you give your users a .dotm template, it can hold the building block. Is there some reason to have the building block in a separate file?
Is there some reason to have the building block in a separate file?:

YES, I need to have the original template for the rest of the workers; each one of them works the template independently and they need to save the individual work in their own folders.

Is there a way to replace this line with this one, asking the user which path to save it to?

Marked bold line, replace

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 this other line or something similar:

Application.Templates( _
"L:\02.- ATESTADOS 2022\ATESTADOS PAMPLONA\2. ACCIDENTES CIRCULACION" & AT-1234568 & "\BAEI – INFORME TECNICO.docm"). _
BuildingBlockEntries("INICIO Y EXPOSICION DE HECHOS").Insert Where:=Selection.Range, RichText _
:=True

AT-1234568 Name that the user is asked for, because I don't know what name he is going to give to that folder.
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 11:52 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