+ Reply to Thread
Results 1 to 24 of 24

Use Sheet Label as Clickable Link to

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Use Sheet Label as Clickable Link to

    Hi all, I'm trying to create a link to a file using a label and use click event to open it.
    However, preferrably I'd like to leave the caption alone and use maybe a mouse over
    event to load a string(path to file) the path would be set in another module code

    Please Login or Register  to view this content.
    I tried to make public dim followlink as string
    so any sub using followlink would recogize the path.
    However, I have yet to set that up right

    Please Login or Register  to view this content.
    In my efforts using the last example code, I'm getting an object required error.

    Any helps in my endeavor is appreciated.

    Thanks,
    BDB
    Last edited by bdb1974; 05-02-2011 at 12:46 PM. Reason: Adjusted code tag

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Use Sheet Label as Clickable Link to

    o BDB,

    Change "Documents" to "Workbooks"...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    ... and didn't mention but will also be openning pdf's.

    BDB

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Use Sheet Label as Clickable Link to

    Hello BDB,

    You can open any document using the Shell command...
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    I'm getting a file not found run time error code 53.

    I tried to research using Shell to open a file using vba and found some other examples like:
    Please Login or Register  to view this content.
    I tried doing the later like,

    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Still getting file not found, though I know the path is correct.

    BDB

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Use Sheet Label as Clickable Link to

    Hello BDB,

    Did you try the example I posted? It should work. The Shell method only requires the file path and name. The second argument is to control how the window will be displayed.

  7. #7
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Yes, but when I tried it exactly as you stated, I get a Run-time error '5:
    Invalid procedure call or argument.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Use Sheet Label as Clickable Link to

    Hello BDB,

    You don't mention which version of Excel you using, but this should work up to 2007. The examples you cited are different from anything I have ever seen for Shell. Where did you find them?

  9. #9
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Leith,

    I'm using 2003. The information that I had provided came from:
    http://www.mvps.org/dmcritchie/excel/shell.htm

    Today, I've started to go back over the code to try and figure out why it's stating "File Not Found". I tried again (3) configurations so far w/ no success.


    BDB

  10. #10
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    In my efforts, I tried to test for the existence of the file and path by using fso.

    Please Login or Register  to view this content.
    This did verify the correct path.

    Still curious as to how to make an path to an external an object so I could use the following:
    Please Login or Register  to view this content.

    BDB
    Last edited by bdb1974; 04-27-2011 at 02:06 PM.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Use Sheet Label as Clickable Link to

    Hello BDB,

    Can you post the workbook? I would like to run it on my system and see if it behaves the same way.

  12. #12
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Leith,
    Sorry for the delay, it took me a little while to make an example.

    I didn't setup a click event for the 2nd label.

    To run, Open combobox and select an item. A link should appear in both of the labels.
    Click Label1 , then the file should open when working correctly.
    Thanks,

    BDB
    Attached Files Attached Files

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Use Sheet Label as Clickable Link to

    Hello BDB,

    Thanks for taking the time to do all that. Each Excel file has a PDF file it is to open, correct?

  14. #14
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Correct. The name is the same. Only difference is the extension.
    Label 1 opens excel wb's
    Label2 opens pdf's

    Is there a way to have the label hold the string for the file path w/o
    changing the labels caption ( visible text) ?
    Or have the click event fetch the dynamically assigned path from another source?



    BDB
    Last edited by bdb1974; 04-27-2011 at 04:42 PM.

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Use Sheet Label as Clickable Link to

    Hello BDB,

    Okay, I have it working. I love the API. Copy this code into Module1.
    Please Login or Register  to view this content.


    Label1_Click Event Code
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Leith,

    Can you please post the working example, or give further instructions on the placement
    of code for the "Click Event". I've pasted the first part into Module1 as stated.

    But the second section, I'm having trouble following.
    Where am I suppose to place it or associate it with the Label1_Click ( ) ?

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Leith,

    Could you please post the working workbook?


    Thanks,

    BDB

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Use Sheet Label as Clickable Link to

    Hello BDB,

    I only tested the Label1_Click() event code calling the API code. If you want me to fix the workbook so it is completely functional, I will. You need to tell me how this is intended to work with the ComboBox and ListBox and the Labels.

  19. #19
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    What I sent to you was only an example to show the label_click to open a file setup needed. Though I don't think the function of the listbox is relevant ,the listbox serves as a holder for the group of items the end user selects and uses from a combobox1 & 2
    on the sheet. In a reverse action, the user can remove items from the listbox. When the user exercises this action/event, one of the reactions is,the item in combobox2 used to build the selected item in the listbox will be set/select w/code to become the combobox2.value in use. I have this working. I also have two cell where the text serves as a dynamic hyper link to a pdf file and another to an excel file depending on the combobox1items being selected. The only problem is using cells is that I cannot group or rearrange the placement on the sheet like you can with objects.

    The only problem using a label that I see is you have to use the caption to hold the file path for a click event. That's very unattractive and leaves the user looking at two labels with a string of text going outside the visible range of the label and not really knowing what purpose they serve.. So I'm wondering how it would be to use a two labels in pairs that sit ontop of each other. The button on top(front) could serve as the link name and the bottom on bottom(back) could serve as the path holder. A Click event on the top button then could retrieve the path from the back button caption. Placing a button on top of another would give the appearance of a single button.

    Your more than welcome to construct that for me if you like, however, since my exeperiance with API's is virtually nil, I'm having a hard time following and understanding quite how to get the code you posted to work. So if you could put together an working example or you could ellaborate more on the setup of the code, I probably could get it to work myself.

    Either way, I really do appreciate your assistance and mentoring.

    Thanks,

    BDB
    Last edited by bdb1974; 04-29-2011 at 01:07 PM.

  20. #20
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Leith,

    Any chance I can get a working example from what I have posted?

    Thanks


    BDB

  21. #21
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Still looking for help on this.

    I kinda of took a diverted path into trying to understand the use of API and help resolve my problem.

    I made a very simple example workbook for openning an directory using the shell command. I put the following into a standard module.


    Please Login or Register  to view this content.
    Running the macro, I was expecting this to work. However, nothing seems to happens.
    I get no windows explorer window popping up. Does anyone know what could be preventing this code from working?

    BTW, this was taken from :
    http://vbadud.blogspot.com/2009/01/h...using-vba.html

    Thanks for any assistance,

    BDB

  22. #22
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Ok, I guess, I posted this reply too soon. I just assumed the folder C:\Temp
    was there. It wasn't, only C:\Tmp So, once I createdthe folder and re-ran, it did open.

    So, nothing is wrong with the code to Open a Folder in Windows Explorer using VBA
    or my operating system. Now, if I can figure how to get it to point to a specific file and
    have it open it with my label click.

    Thanks to all,

    BDB

  23. #23
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    If I do something like this:
    Please Login or Register  to view this content.
    What would I need to use for the following:
    full path to program = ?
    "<arguments>" = ?
    "<run in folder>" = ?

    And can I set the code up w/o the RetVal = ?

    Thanks,

    BDB

  24. #24
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Use Sheet Label as Clickable Link to

    Solved!

    For any interested parties,

    This turns out to be a pretty simple procedure but finding it wasn't so simple for me.

    I put the following into a basic module:

    Please Login or Register  to view this content.
    Then in my worksheet

    Please Login or Register  to view this content.
    Make sure to include the file you want to create a link for into the file path.
    C:/test/testfile.pdf
    C:/test/testfile.xls

    Regards,

    BDB
    Last edited by bdb1974; 05-02-2011 at 12:50 PM.

+ 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