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?