+ Reply to Thread
Results 1 to 18 of 18

VBA to determine dynamic path of linked workbook file

  1. #1
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    VBA to determine dynamic path of linked workbook file

    I'm not an expert on the VBA and struggle to build a string for a path and file:

    I have a workbook ?Inc(Auto).xls? that is linked to another workbook, ?GLB.xls?, that is saved in the same folder as ?Inc(Auto).xls?

    Since these files are copied together to other folders by users, I would like to obtain the date and time of ?GLB.xls? in the ?newly? saved user?s folder by running VBA code to have the result pasted in Inc(Auto).xls in cell C2

    My problem is with creating the string name ?MyFullPath?. I?m missing something here? Any help will be valuable.


    Sub GetFildeDateTime()
    Dim DResult As Date
    Dim MyPath, MyFile, MyFullPath As String

    MyPath = Application.ActiveWorkbook.Path
    MyFile = "\GLB.xls"
    MyFullPath = MyPath + MyFile

    DResult = FileDateTime(MyFullPath)
    Range("C2") = "Last updated: " & DResult
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    CHANGE
    Please Login or Register  to view this content.
    TO

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA to determine dynamic path of linked workbook file

    Hi carlmon

    Thx for the reply.

    I get an error directing at DResult

    Run-time error '5':
    Invalid procedure call or argument

  4. #4
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    CHANGE
    Please Login or Register  to view this content.
    TO
    Please Login or Register  to view this content.
    AND SEE IF THAT HELPS

  5. #5
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA to determine dynamic path of linked workbook file

    Regrettably, the same message appears directing at DResult :-(

  6. #6
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    you're getting the procedure argument because it can't find the file you are referencing... you need to look in your locals window and see if MyFullPath matches the file you want to reference

  7. #7
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA to determine dynamic path of linked workbook file

    Thx for your diligence, carlmon.

    Hence my struggle ☹

    When I refer to the stagnant file location, I do get the right date and time.
    Example
    DResult = FileDateTime("E:\OD\My Documents at work\ SBG\Finance\Income Statement\UCE\GLB.xls")
    But the problem is building the dynamic MyFullPath for GLB.xls between the brackets ( )

  8. #8
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    is your active workbook found here: "E:\OD\My Documents at work\ SBG\Finance\Income Statement\UCE" ??

  9. #9
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA to determine dynamic path of linked workbook file

    Indeed it is.

  10. #10
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    The only thing that I can see going wrong is if you are running the code from a workbook that is not located there. There should be no reason that you are getting an error... what is dynamic about the file location, why not hard code it?

  11. #11
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA to determine dynamic path of linked workbook file

    Perhaps my initial explanation is a bit wonky.

    Inc(Auto).xls is linked to GLB.xls. These two files are saved in the same location. Users copy the two files to their own specific locations. Instead of hard coding the new file locations for each user, it would be preferable if the location could be dynamically updated with VBA.

  12. #12
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    brother, just use this code then:
    Please Login or Register  to view this content.
    assuming you want to update the save date for the workbook that they are in.. ?

  13. #13
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA to determine dynamic path of linked workbook file

    Thx bro.
    The problem is that it will return the 'File Date and Time' for Inc(Auto) instead of GLB.xls.
    GLB.xls is a fin-system downloaded file that is replaced, for instance, weekly. Hence, the 'date and time' of the file is displayed in Inc(Auto) as confirmation that the latest downloaded file, GLB.xls was linked.

  14. #14
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    is there any commonality of where each user saves this GLB file?

  15. #15
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA to determine dynamic path of linked workbook file

    Unfortunately not. It would have made life easier though.

  16. #16
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    I'm going to re-create your situation on my end and see what I can do to fix it

  17. #17
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: VBA to determine dynamic path of linked workbook file

    it works for me... are you sure it's an .xls file and not the default .xlsx?

  18. #18
    Registered User
    Join Date
    07-28-2022
    Location
    South Africa North West
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA to determine dynamic path of linked workbook file

    Hi, carlmon. Yep, my file is .xls
    Would you mind sharing your test file? Perhaps I can have a look at it and compare it to my own.
    Truly a strange phenomenon indeed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Printing PDFs with a File Path linked to a cell.
    By HarryGreenwood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2018, 09:38 AM
  2. [SOLVED] File Path Reference Linked Workbook Cell Values
    By Pavel001 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-30-2016, 04:38 PM
  3. Find filename and path of a linked file in another cell
    By Tsangman007 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-02-2015, 01:35 AM
  4. Creating Dynamic Folders/WorkBook from a Sheet with Dynamic Path.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 03-28-2011, 05:42 AM
  5. Reducing Linked File Path / Formula
    By SamuelT in forum Excel General
    Replies: 5
    Last Post: 11-21-2007, 11:46 AM
  6. [SOLVED] Linked file in same folder but unknown path
    By Christy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-04-2005, 02:05 PM
  7. Making path of linked cell dynamic
    By Negentropy in forum Excel General
    Replies: 3
    Last Post: 09-24-2005, 04:02 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1