Home

Word 365 attached template from Onedrive shows URL instead of path

%3CLINGO-SUB%20id%3D%22lingo-sub-671159%22%20slang%3D%22en-US%22%3EWord%20365%20attached%20template%20from%20Onedrive%20shows%20URL%20instead%20of%20path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-671159%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20Word%2C%20using%20VBA%20in%20a%20template%2C%20I%20want%20to%20insert%20data%20from%20a%20text%20file%20to%20the%20document.%20I%20have%20saved%20the%20template%20and%20the%20text%20file%20in%20the%20same%20location.%20In%20VBA%20I%20use%20the%20statement%20%22ActiveDocument.AttachedTemplate.Path%22%20to%20find%20the%20location%20of%20the%20text%20file.%3C%2FP%3E%3CP%3ENow%2C%20my%20template%20and%20text%20file%20are%20in%20SharePoint%2C%20which%20I%20have%20synchronized%20to%20my%20local%20Onedrive%3A%20C%3A%5CUsers%5C%5Bmyname%5D%5COneDrive%20-%20%5BSharePoint%20site%5D%20etc.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20my%20own%20computer%2C%20this%20works%20fine.%20But%20on%20my%20customer's%20computer%20(for%20who%20I've%20created%20the%20template)%20the%20template%20gives%20an%20error%2C%20because%20it%20cannot%20find%20the%20text%20file.%20The%20problem%20is%20easily%20found%2C%20because%20when%20I%20look%20for%20the%20location%20of%20the%20template%20it%20shows%20the%20SharePoint-URL%20instead%20of%20the%20local%20Onedrive-location.%3C%2FP%3E%3CP%3EI%20have%20tried%20the%20following%20options%20for%20document%20creation%3A%20double%20click%20the%20template's%20name%20in%20the%20File%20Explorer%20and%20%26gt%3BFile%20%26gt%3BNew%20in%20Word.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20question%3A%20how%20can%20I%20make%20Word%20show%20the%20local%20OneDrive%20location%20of%20the%20attached%20template%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-676665%22%20slang%3D%22en-US%22%3ERe%3A%20Word%20365%20attached%20template%20from%20Onedrive%20shows%20URL%20instead%20of%20path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-676665%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F221885%22%20target%3D%22_blank%22%3E%40Jos%C3%A9%20Spanjaard%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20few%20questions%20to%20trigger%20a%20few%20ideas%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Did%20you%20try%20hard%20coding%20the%20path%20rather%20than%20the%20dynamic%20one%20you've%20used%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%20The%20path%20location%20for%20your%20client%20will%20be%20different%20to%20yours%2C%20does%20the%20client%20have%20the%20files%20sync'd%20to%20their%20computer%3F%20This%20would%20also%20entail%20them%20having%20the%20right%20file%20permissions%20to%20access%20the%20document.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20a%20great%20weekend%20ahead!%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3ECheers%3CBR%20%2F%3EDamien%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-677256%22%20slang%3D%22en-US%22%3ERe%3A%20Word%20365%20attached%20template%20from%20Onedrive%20shows%20URL%20instead%20of%20path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-677256%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89704%22%20target%3D%22_blank%22%3E%40Damien%20Rosario%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20suggestions.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20remembered%20that%20my%20files%20were%20copied%20directly%20from%20the%20File%20Explorer%20to%20a%20mapped%20OneDrive-folder%20instead%20of%20synching%20them%20from%20SharePoint.%20These%20directly%20copied%20files%20are%20working%20fine.%3C%2FP%3E%3CP%3ETo%20be%20sure%20I%20am%20working%20with%20a%20proper%20environment%2C%20I%20completely%20removed%20OneDrive%20from%20my%20computer%2C%20re-installed%20it%20and%20synch'd%20again.%20Now%2C%20I%20am%20facing%20the%20same%20problem%20as%20my%20client%20(which%20is%20'good%20'%20%3A)%3C%2Fimg%3E%20)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%2C%20I%20have%20checked%20your%20suggestions%3A%3C%2FP%3E%3CP%3E1.%20I%20have%20hard%20coded%20the%20path%20(both%20the%20local%20Onedrive-mapping%20as%20the%20SharePoint-URL)%2C%20but%20the%20result%20is%20the%20same%3A%20Word%20cannot%20find%20or%20read%20the%20text%20file.%3C%2FP%3E%3CP%3E2.%20The%20files%20are%20indeed%20synch'd%20to%20the%20computer%20and%20I%20have%20the%20correct%20permissions%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20I%20need%20a%20checkbox%20where%20Word%2FWindows%20accepts%20the%20mapped%20OneDrive%20folder%20name%20%E2%80%A6%20Any%20ideas%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThx%2C%20Jos%C3%A9%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-679033%22%20slang%3D%22en-US%22%3ERe%3A%20Word%20365%20attached%20template%20from%20Onedrive%20shows%20URL%20instead%20of%20path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-679033%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F221885%22%20target%3D%22_blank%22%3E%40Jos%C3%A9%20Spanjaard%3C%2FA%3E%26nbsp%3B%20You%20can%20pick%20up%20the%20current%20user's%20local%20OneDrive%20folder%20path%20from%20the%20registry%2C%20using%20code%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EDim%20myWS%20As%20Object%0A%0AFunction%20RegValueExists(i_RegKey%20As%20String)%20As%20Boolean%0A%20%20On%20Error%20GoTo%20ErrorHandler%0A%20%20'try%20to%20read%20the%20registry%20value%0A%20%20myWS.RegRead%20i_RegKey%0A%20%20'value%20was%20found%0A%20%20RegValueExists%20%3D%20True%0A%20%20Exit%20Function%0A%20%20%0AErrorHandler%3A%0A%20%20'key%20was%20not%20found%0A%20%20RegValueExists%20%3D%20False%0AEnd%20Function%0A%0AFunction%20RegValueRead(i_RegKey%20As%20String)%20As%20String%0A%20%20On%20Error%20Resume%20Next%0A%20%20'read%20value%20from%20registry%0A%20%20RegValueRead%20%3D%20myWS.RegRead(i_RegKey)%0AEnd%20Function%0A%0ASub%20testOneDrive()%0A%20%20%20%20Dim%20strOneDriveKey%20As%20String%0A%20%20%20%20Dim%20strOneDriveFolder%20As%20String%0A%20%20%20%20%0A%20%20%20%20strOneDriveKey%20%3D%20%22HKEY_CURRENT_USER%5CSoftware%5CMicrosoft%5COneDrive%5CUserFolder%22%0A%20%20%20%20%0A%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20'access%20Windows%20scripting%0A%20%20%20%20Set%20myWS%20%3D%20CreateObject(%22WScript.Shell%22)%0A%20%20%20%20If%20myWS%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20MsgBox%20%22Could%20not%20access%20scripting%20shell%22%0A%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20End%20If%0A%20%20%20%20%0A%20%20%20%20If%20RegValueExists(strOneDriveKey)%20Then%0A%20%20%20%20%20%20%20%20strOneDriveFolder%20%3D%20RegValueRead(strOneDriveKey)%0A%20%20%20%20End%20If%0A%20%20%20%20%0A%20%20%20%20If%20strOneDriveFolder%20%26lt%3B%26gt%3B%20%22%22%20Then%0A%20%20%20%20%20%20%20%20MsgBox%20strOneDriveFolder%2C%20vbInformation%2C%20%22OneDrive%20User%20Folder%22%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20MsgBox%20%22Folder%20not%20found%22%2C%20vbExclamation%2C%20%22OneDrive%20User%20Folder%22%0A%20%20%20%20End%20If%0AEnd%20Sub%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
José Spanjaard
New Contributor

In Word, using VBA in a template, I want to insert data from a text file to the document. I have saved the template and the text file in the same location. In VBA I use the statement "ActiveDocument.AttachedTemplate.Path" to find the location of the text file.

Now, my template and text file are in SharePoint, which I have synchronized to my local Onedrive: C:\Users\[myname]\OneDrive - [SharePoint site] etc.

 

On my own computer, this works fine. But on my customer's computer (for who I've created the template) the template gives an error, because it cannot find the text file. The problem is easily found, because when I look for the location of the template it shows the SharePoint-URL instead of the local Onedrive-location.

I have tried the following options for document creation: double click the template's name in the File Explorer and >File >New in Word.

 

My question: how can I make Word show the local OneDrive location of the attached template?

3 Replies

Hi @José Spanjaard 

 

A few questions to trigger a few ideas:

 

1. Did you try hard coding the path rather than the dynamic one you've used?

 

2. The path location for your client will be different to yours, does the client have the files sync'd to their computer? This would also entail them having the right file permissions to access the document.

 

Have a great weekend ahead!

Cheers
Damien

Hi@Damien Rosario 

 

Thanks for your suggestions.

 

I just remembered that my files were copied directly from the File Explorer to a mapped OneDrive-folder instead of synching them from SharePoint. These directly copied files are working fine.

To be sure I am working with a proper environment, I completely removed OneDrive from my computer, re-installed it and synch'd again. Now, I am facing the same problem as my client (which is 'good ' :) )

 

Then, I have checked your suggestions:

1. I have hard coded the path (both the local Onedrive-mapping as the SharePoint-URL), but the result is the same: Word cannot find or read the text file.

2. The files are indeed synch'd to the computer and I have the correct permissions

 

I think I need a checkbox where Word/Windows accepts the mapped OneDrive folder name … Any ideas?

 

Thx, José

 

@José Spanjaard  You can pick up the current user's local OneDrive folder path from the registry, using code like this:

 

Dim myWS As Object

Function RegValueExists(i_RegKey As String) As Boolean
  On Error GoTo ErrorHandler
  'try to read the registry value
  myWS.RegRead i_RegKey
  'value was found
  RegValueExists = True
  Exit Function
  
ErrorHandler:
  'key was not found
  RegValueExists = False
End Function

Function RegValueRead(i_RegKey As String) As String
  On Error Resume Next
  'read value from registry
  RegValueRead = myWS.RegRead(i_RegKey)
End Function

Sub testOneDrive()
    Dim strOneDriveKey As String
    Dim strOneDriveFolder As String
    
    strOneDriveKey = "HKEY_CURRENT_USER\Software\Microsoft\OneDrive\UserFolder"
    
    On Error Resume Next
    'access Windows scripting
    Set myWS = CreateObject("WScript.Shell")
    If myWS Is Nothing Then
        MsgBox "Could not access scripting shell"
        Exit Sub
    End If
    
    If RegValueExists(strOneDriveKey) Then
        strOneDriveFolder = RegValueRead(strOneDriveKey)
    End If
    
    If strOneDriveFolder <> "" Then
        MsgBox strOneDriveFolder, vbInformation, "OneDrive User Folder"
    Else
        MsgBox "Folder not found", vbExclamation, "OneDrive User Folder"
    End If
End Sub
Related Conversations
Extentions Synchronization
Deleted in Discussions on
3 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
38 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies