+ Reply to Thread
Results 1 to 10 of 10

UPDATED - Trying to Create a Hyperlink in VBA and Copy it to Clipboard

  1. #1
    Registered User
    Join Date
    09-08-2023
    Location
    Ontario, Canada
    MS-Off Ver
    Microsoft 365 Office
    Posts
    5

    UPDATED - Trying to Create a Hyperlink in VBA and Copy it to Clipboard

    I have built a UserForm to manage HyperLinks from one worksheet that are related to specific Items on another worksheet.
    To support this, I show a UserForm with a listbox containing the Hyperlinks related to the selected item.
    The Userform also contains: a button to add a new link, a button to delete a link, and a button to open a link.
    I am adding a button to copy a link (to the clipboard). I have built the hyperlink string and copied it to the clipboard.

    I could not post the full Sample String here ---> <a href="url">"Test link number 19"</a>
    but the "url" is properly formed

    I have pasted from the clipboard and the string (as shown above) is returned in both Notepad and Word.
    I am not a developer and feel like I am missing something that should be obvious (or I should have learned by now).
    Would very much appreciate a push in the right direction.

    Code:
    Private Sub CopyButton_Click()
    Dim CopyToClip As Object
    Dim LinkString As String
    Set CopyToClip = CreateObject("HtmlFile")
    LinkString = "<a href=" & Chr(34) & URLTxtBox & Chr(34) & ">" & Chr(34) & NameTxtBox & Chr(34) & "</a>"
    CopyToClip.ParentWindow.ClipboardData.SetData "text", LinkString
    End Sub
    Last edited by Him, just him; 09-11-2023 at 11:45 AM. Reason: Added detail

  2. #2
    Registered User
    Join Date
    09-08-2023
    Location
    Ontario, Canada
    MS-Off Ver
    Microsoft 365 Office
    Posts
    5

    Re: Trying to Create a Hyperlink in VBA and Copy it to Clipboard

    Folks,

    Is there more info that I need to provide on this issue?
    Can anyone point me in a direction to help me make this work?
    Any assistance would be appreciated.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Trying to Create a Hyperlink in VBA and Copy it to Clipboard


    Your initial post is confusing as you use Excel term for a non Excel need : an Excel hyperlink has nothing to do with html code !
    Thus without any workbook attachment neither a crystal clear explanation of what you expect for …

  4. #4
    Registered User
    Join Date
    09-08-2023
    Location
    Ontario, Canada
    MS-Off Ver
    Microsoft 365 Office
    Posts
    5

    Re: Trying to Create a Hyperlink in VBA and Copy it to Clipboard

    I apologize if my earlier explanations were not clear enough.
    I have attached a sample file to show the issue.

    The steps to replicate the issue are:
    1 Open the file, go to the "Items" tab and click on cell C2
    2 In the UserForm titled "Source / Item Number: xxx / 1", press the "Links (25)" button at the bottom of the form
    . UserForm = ufItemDisplay
    3 in the UserForm titled "Links for Source / Item No: xxx / 1", select a Link (a row) from the listbox
    . Userform = ufLinksDisplay
    4 Press the "Copy Link" button
    . Sub = CopyButton_Click
    5 The hyperlink string is shown in the box labelled "Sample Link" and is copied to the Clipboard for diagnostics only (will be deleted in the final version.

    The Issue is:
    This is not creating an actual hyperlink.
    Pasting this string does not create a hyperlink.
    I want to create a hyperlink and copy it to the Clipboard from the "Copy Link" button.

    Any assistance is appreciated.
    Attached Files Attached Files
    Last edited by Him, just him; 09-11-2023 at 10:04 AM.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Trying to Create a Hyperlink in VBA and Copy it to Clipboard


    Quote Originally Posted by Him, just him View Post
    2 In the UserForm titled "Source / Item Number: xxx / 1", press the "Links (25)" button at the bottom of the form
    When I click this button that crashes 'cause of 'ColumnWidths' …

    Hoping another helper can test with the same 'current versions' as yours.

  6. #6
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,224

    Re: UPDATED - Trying to Create a Hyperlink in VBA and Copy it to Clipboard

    Marc L, replace commas with semicolons.

    Artik

  7. #7
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,985

    Re: UPDATED - Trying to Create a Hyperlink in VBA and Copy it to Clipboard

    For me, if you break after this line then the text is in the clipboard, but it's lost once the Sub ends.
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: UPDATED - Trying to Create a Hyperlink in VBA and Copy it to Clipboard


    Thanks Artik but as I got other issue I'm still out …

  9. #9
    Registered User
    Join Date
    09-08-2023
    Location
    Ontario, Canada
    MS-Off Ver
    Microsoft 365 Office
    Posts
    5

    Re: UPDATED - Trying to Create a Hyperlink in VBA and Copy it to Clipboard

    Folks,

    I appreciate the attention you are giving to my issue.

    Thank you.

  10. #10
    Registered User
    Join Date
    09-08-2023
    Location
    Ontario, Canada
    MS-Off Ver
    Microsoft 365 Office
    Posts
    5

    Re: UPDATED - Trying to Create a Hyperlink in VBA and Copy it to Clipboard

    I figured a way to get the hyperlink copied to the clipboard.
    Thanks for your attention.
    No further assistance needed on this one.

+ 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. Replies: 9
    Last Post: 06-20-2023, 04:58 AM
  2. [SOLVED] VBA loop through column and extract embedded hyperlink and create clickable hyperlink
    By Jay S. in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2021, 04:42 PM
  3. Create string to copy to clipboard
    By her.rockstar in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 02-06-2019, 01:31 PM
  4. [SOLVED] Get a hyperlink onto clipboard?
    By terrypin in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 12-11-2017, 11:39 AM
  5. Replies: 3
    Last Post: 04-17-2017, 10:32 AM
  6. macro to move 1 cell left and paste CURRENT clipboard content as HYPERLINK
    By sgoesef in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2013, 01:31 PM
  7. Replies: 3
    Last Post: 10-21-2011, 06:59 AM

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