0

I have one Excel workbook thats is sync local and online, if a open with onedrive running my excel reconize this workbook how online file, the excel 365 has a option (file>information>copy local path) if a file is also save local.

SendKeys "%ail~" 'this line get the text, end send to clipboard, works one time, but now nothing is send.

Sorry my english.

Sub TestPath()
    Dim wb As Workbook
    Dim LocalString         As DataObject
    Dim CamLocalComplete    As String 'path file + name file
    Dim WorkBookName        As String 'name file
    Dim CamLocal            As String 'must be only local path file
    Set LocalString = New DataObject
    
    WorkBookName = ThisWorkbook.Name
    Set wb = Workbooks(WorkBookName)
    wb.Activate
    Application.Wait Now + TimeValue("00:00:01")
    'File > Informations > Copy local path
    SendKeys "%ail~"  'this line get the text send to clipboard, works one time, but now
    Application.Wait Now + TimeValue("00:00:01")
    'Back plan
    SendKeys "{ESC}"
    'Get cliboard text
    LocalString.GetFromClipboard
    CamLocalComplete = LocalString.GetText
    CamLocal = Left(CamLocalComplete, InStrRev(CamLocalComplete, "\") - 1)
    Range("E26").Value = CamLocal
End Sub
BigBen
  • 46,229
  • 7
  • 24
  • 40
  • IMHO this is the wrong approach to get the local file name especially as Sendkeys is not reliable. Please have look [here](https://github.com/cristianbuse/VBA-FileTools) for another approach – Storax May 19 '23 at 19:45
  • 3
    Does this answer your question? [Excel's fullname property with OneDrive](https://stackoverflow.com/questions/33734706/excels-fullname-property-with-onedrive) and the [accepted answer](https://stackoverflow.com/questions/33734706/excels-fullname-property-with-onedrive/73577057#73577057) – Storax May 19 '23 at 19:54
  • This approach is actually possible but not recommended. If you still want to try it out, have a look at [this answer](https://stackoverflow.com/a/75751584/12287457), where this approach is discussed in detail. If you just want the best solution, follow the link to the accepted answer in the comment by @Storax. – GWD May 19 '23 at 20:32
  • Hi guys the post @Storax work for me https://stackoverflow.com/users/saves/5457834 thanks – Alex Nunes May 22 '23 at 18:33

0 Answers0