Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-11-2022, 04:18 PM
jamu jamu is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2021
Novice
How would it be possible to display the paths of fields in footers?
 
Join Date: Mar 2022
Posts: 11
jamu is on a distinguished road
Default How would it be possible to display the paths of fields in footers?


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.
Reply With Quote
  #2  
Old 04-11-2022, 08:26 PM
Guessed's Avatar
Guessed Guessed is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 04-11-2022, 08:56 PM
macropod's Avatar
macropod macropod is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Also, it is not necessary to show field codes to replace their contents.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 04-11-2022, 09:29 PM
jamu jamu is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2021
Novice
How would it be possible to display the paths of fields in footers?
 
Join Date: Mar 2022
Posts: 11
jamu is on a distinguished road
Default

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?
Reply With Quote
  #5  
Old 04-11-2022, 09:37 PM
macropod's Avatar
macropod macropod is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #6  
Old 04-11-2022, 11:20 PM
jamu jamu is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2021
Novice
How would it be possible to display the paths of fields in footers?
 
Join Date: Mar 2022
Posts: 11
jamu is on a distinguished road
Default

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.
Reply With Quote
  #7  
Old 04-11-2022, 11:31 PM
macropod's Avatar
macropod macropod is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Have you looked at the field codes after running the macro?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 04-12-2022, 02:40 AM
jamu jamu is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2021
Novice
How would it be possible to display the paths of fields in footers?
 
Join Date: Mar 2022
Posts: 11
jamu is on a distinguished road
Default

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?
Reply With Quote
  #9  
Old 04-13-2022, 12:19 AM
macropod's Avatar
macropod macropod is offline How would it be possible to display the paths of fields in footers? Windows 10 How would it be possible to display the paths of fields in footers? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I asked:
Quote:
Originally Posted by macropod View Post
Have you looked at the field codes after running the macro?
Your answer:
Quote:
Originally Posted by jamu View Post
Yes, with the Python script result the fields were not updated, it came an error message that the file could not be found.
tells me you're not looking at the field codes.

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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How would it be possible to display the paths of fields in footers? VBA to display and choose merge fields JamesWood Word VBA 2 12-16-2020 02:17 PM
How would it be possible to display the paths of fields in footers? How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) elocution Word VBA 3 12-11-2018 02:42 PM
How would it be possible to display the paths of fields in footers? Word Fields and Relative Paths to External Files 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:16 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