+ Reply to Thread
Results 1 to 10 of 10

Link to file if exist

  1. #1
    Registered User
    Join Date
    12-01-2010
    Location
    Belgrade
    MS-Off Ver
    Excel 2003
    Posts
    12

    Link to file if exist

    Hi,

    I am trying to create macro in excel 2007.
    I have excel document in folder together with other files (.pdf, .doc, .xls.....) in excel document I have column (i2,i3,i4...) inside that column I have exact file name (documentName.pdf, documentName.doc....). I need macro that would search for that particular file (if exist) in the same folder and add a link to that file. Something like: i2=documentName.pdf - if that file exist add hyperlink to k2 "link to file" (or "no file on disk" if file doesn't exist), and continue loop trough all "i" columns.

    Thanks so much for help.
    Last edited by bongobuda; 12-06-2010 at 12:42 PM.

  2. #2
    Registered User
    Join Date
    12-01-2010
    Location
    Belgrade
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Link to file if exist

    Hi guys,

    I am still struggling with this one.

    I managed so far to extract all files from folder and to hyperlink them. Only problem left is rows are not matching up, data is not in order. I have now column "F" with all file names (that is original data) and new column "K" with with files that exist on folder.

    I need to re-arrange columns "F" and "K" (so that values in "F2,3,4..." is equal to values in "K2,3,4...")

    any help is appreciated,

    here is my current code:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Link to file if exist

    A resource for you to try:

    CREATE HYPERLINKED DIRECTORY LISTING
    Here's a macro for creating a hyperlinked listing of files in a chosen directory that match a certain file type (or all). Macro will list the last modified time stamp as well. A sample file is include on the page:
    Create Hyperlinked Directory Listing
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    12-01-2010
    Location
    Belgrade
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Link to file if exist

    Thanks JBeaucaire,

    I had that part working properly, my problem was placing files next to original values. That piece was essential since people needed to monitor files uploaded.

    I managed somehow by looping every predefined value and then in each loop I am looping files again to find one with the same name (if exist). Everything is working as expected, but drawback is really long time to populate sheet ( I am having thousands of files in one sheet)

    Here is my final code in case someone need it, and if anybody has idea how I can speed this up a bit I'll really appreciate.

    Thanks again,

    Please Login or Register  to view this content.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Link to file if exist

    My Link was intended to give you a potentially faster routine you could use/modify.

    For yours, the abundant use of ActiveCell means you are physically accessing the worksheet over and over again which is inherently slow, unfortunately. A wholesale rewrite of your macro is the only way to possibly speed it up.

  6. #6
    Registered User
    Join Date
    12-01-2010
    Location
    Belgrade
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Link to file if exist

    Thanks JBeaucaire,

    True, make sense completely. Any suggestions, this is my first code I ever did in Excel. I even had idea connecting this on web server and to register excel sheet as DB source, than with SQL I can do easily much more since I am more conversant with that.

    I would prefer doing it completely with Excel, since it is much more convenient for people that are supposed to use it.

    Thanks again for help, I really appreciate it.

  7. #7
    Registered User
    Join Date
    12-01-2010
    Location
    Belgrade
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Link to file if exist

    Hi JBeaucaire,

    Actually I found your example "Line Up Matches - Problem#2" which with combining with "Create Hyper linked Directory Listing" is perfect solution for me. I did some testing today and it looks perfect. I have testing excel document with 15 records and everything is working perfect, but when I run it on real excel document with 15 thousands records it messes up a bit my original records. It creates blanks and it doesn't match properly.

    I have columns in my document "A" to "J" where rows cannot be sorted or changed in any way - they have to remain as they are. Then I am inserting files with hyperlinks in columns "K" to "N" where files are extracted alphabetically. Than I have couple of more columns from "O" to "S" where is also some original data which cannot be moved.

    Original File name is in columns "F" and newly inserted Hyper linked document is in "K". Those two I have to line up.


    When I use your "Line Up Matches" everything works perfect till last part where items are lining up (ps. I skipped "Sort both section so numbers are ascending in E and F" since I cannot sort my original data)

    Here is my code I am using if you can have a look and give me any suggestion I'll really appreciate.

    Thanks for all help

    Please Login or Register  to view this content.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Link to file if exist

    With nothing I can actually look at, my only real comment right now is the the Line'Em Up macro requires the data to be sorted ascending. If the macro itself can't sort the data to make sure, then....?

  9. #9
    Registered User
    Join Date
    12-01-2010
    Location
    Belgrade
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Link to file if exist

    Thanks JBeaucaire,

    I left it with loop as it was before, I just optimized it a bit, so it is sort of reasonable speed.

    Thanks for help I really appreciate it

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Link to file if exist

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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