与OneDrive同步后,ThisWorkbook.FullName返回URL.我想要磁盘上的文件路径 [英] ThisWorkbook.FullName returns a URL after syncing with OneDrive. I want the file path on disk

查看:182
本文介绍了与OneDrive同步后,ThisWorkbook.FullName返回URL.我想要磁盘上的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OneDrive上有一本工作簿.通常,ThisWorkbook.FullName返回磁盘上的路径:

I have a workbook on OneDrive. Usually, ThisWorkbook.FullName returns a path on disk:

c:\Users\MyName\OneDrive - MyCompany\BlaBla\MyWorkbook 09-21-17.xlsb

但是在VBA中进行了一系列操作之后,我手动将文件保存到备份文件夹并使用新日期重命名当前文件,OneDrive同步并且ThisWorkbook.FullName返回URL:

But after a set of operation in VBA where I manually save the file to a backup folder and rename the current file with a new date, OneDrive syncs and ThisWorkbook.FullName returns a URL:

https://mycompany.sharepoint.com/personal/MyName_Company_com/Documents/mycompany/Apps/BlaBla/MyWorkbook 10-21-17.xlsb

即使ThisWorkbook.FullName返回URL,我也需要磁盘的路径.

I need the path to disk, even when ThisWorkbook.FullName returns a URL.

如果我想一起砍东西,可以在执行操作之前保存路径,但是我希望能够随时检索磁盘路径.

If I wanted to hack something together, I could save the path before my operations, but I want to be able to retrieve the disk path at any time.

我已经看到其他人一起破解了一些程序,例如 ,但它或多或少只是将URL重新格式化为磁盘上的路径.这样做不可靠,因为URL路径和磁盘路径并不总是具有相同的目录结构(与上面示例中给出的目录结构相比,请参见链接过程中进行的重新格式化).

I've seen some procedures other people have hacked together, like this one, but it more or less just reformats the URL into a path on disk. Doing this isn't reliable as the URL path and the disk path don't always have the same directory structure (see the reformatting done in the linked procedure compared to the directory structures I give as examples above).

即使在线同步并且ThisWorkbook.FullName返回URL,是否存在可靠,直接的方法来返回工作簿磁盘上的路径?

Is there a solid, direct, way of returning the path on disk of the Workbook, even if it's syncing online and ThisWorkbook.FullName is returning a URL?

推荐答案

我唯一能想到的就是在知道localPath时(在开始保存和同步之前)缓存localPath,然后使用缓存的localPath和工作簿的Name重建"路径:

The only thing I can think of, is to cache the localPath when you know you have it (before you start saving & synchronizing), and then "rebuild" the path using the cached localPath and the workbook's Name:

Public Sub Test()
    Dim localPath As String
    With New FileSystemObject

        With .GetFolder(ActiveWorkbook.Path)
            localPath = .Path
        End With

        'SaveAs/synchronize...

        Debug.Print .BuildPath(localPath, ActiveWorkbook.Name)

    End With
End Sub

这篇关于与OneDrive同步后,ThisWorkbook.FullName返回URL.我想要磁盘上的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆