![]() |
#1
|
|||
|
|||
![]() How would it be possible to display the paths of fields in footers? I tried with ActiveDocument.Fields.ToggleShowCodes but only the paths of fields outside footers are shown. I would then replace the paths as already successfully implemented in the main document with a path I get by running a Python script. The search and replace of the path in the footer unfortunately only works when the path is visible. |
#2
|
||||
|
||||
![]()
You should loop through all the storyranges in the document. The basic vba code structure is repeated on this forum many times. Here is one such example https://www.msofficeforums.com/159190-post2.html
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
![]()
Also, it is not necessary to show field codes to replace their contents.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
![]()
Somehow I always get the error message "The file cannot be found" when I use the path as output of a Python script to replace the field path, but if I select the file via filepicker and specify the path or pass it as a string, the change of the path works without problems. The strange thing is that the path output by Pytohn is completely identical to these.
Does anyone have time to look at the code / know what could be the reason? Here would be the Macors (it's actually one of yours macropod): Code:
Sub Update_Links() ' ' Update_Link Macro Dim Rng As Range, i As Long, vItem As Variant Dim strPythonPath As String Dim strPyScript As String Dim strCmd As String strPythonPath = "C:\Users\a\python.exe" strPyScript = "C:\Users\a\mo\na.py" strCmd = fnShellOutput(strPythonPath & " " & strPyScript) vItem = strCmd 'update fields ' Application.ScreenUpdating = False With ActiveDocument For Each Rng In .StoryRanges With Rng For i = .Fields.Count To 1 Step -1 If .Fields(i).Type = wdFieldLink Then .Fields(i).LinkFormat.SourceFullName = vItem Next For i = .ShapeRange.Count To 1 Step -1 If Not .ShapeRange(i).LinkFormat Is Nothing Then .ShapeRange(i).LinkFormat.SourceFullName = vItem Next For i = .InlineShapes.Count To 1 Step -1 If Not .InlineShapes(i).LinkFormat Is Nothing Then .InlineShapes(i).LinkFormat.SourceFullName = vItem Next End With Next End With ' Application.ScreenUpdating = True MsgBox "Done!" End Sub The goal would be that when opening the file, the filepath stored in the Python program would be used as replacement of the current filepath. Or else I just have a document with many fields to an Excelfile where it has depending on the user a change ending e.g. blabla_max.xlsm and blabla_anton.xlsm and is in a different location, in Python the user is determined then the dropboxpath and then in the dropboxpath after the Excelfile where the ending is derived from the username. Does this make sense? |
#5
|
||||
|
||||
![]()
It's not apparent to me what vItem contains. In needs to contain the source file's fullname, not just the path.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
![]()
Sorry, the actual whole filename is stored in the variable vitem, so path+filename with extension.
e.g "C:\users\a\Desktop\max.xlsm" the macro works if I give it a string like the above or use filpicker to get a file but not if I try to pass the value from the python script altough they all are identical. |
#7
|
||||
|
||||
![]()
Have you looked at the field codes after running the macro?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
![]()
Yes, with the Python script result the fields were not updated, it came an error message that the file could not be found. When using a string with the identical fullfilename or selecting the file the field was updated.
Otherwise how would you replace the excel sheet in the fields of the footer, (it is only 1 field) by another? |
#9
|
||||
|
||||
![]()
I asked:
Your answer: Quote:
It's hardly surprising your field might display erroneous results, since there's nothing in the code you posted to cause them to refresh.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
JamesWood | Word VBA | 2 | 12-16-2020 02:17 PM |
![]() |
elocution | Word VBA | 3 | 12-11-2018 02:42 PM |
![]() |
macropod | Word | 0 | 04-08-2018 05:06 PM |
Pivot table - I cant display item labels when no fields in value area | differentdrummer | Excel | 0 | 12-12-2013 05:13 PM |
How to display sort fields | keith1952 | Word | 1 | 10-31-2011 05:58 AM |