Macro to create hyperlink refuses to work

mal909

New Member
Joined
Aug 5, 2010
Messages
7
Hi All,

it's a while since I've been around these parts, so long in fact I've forgotten my login!:LOL:

I have a marco that takes information from an excel sheet and moves it to a new workbook, saves the workbook in a specific folder (which it creates), with a specific name (based on the data it copied).<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
The information to be saved is unique per row of the original excel sheet. <o:p></o:p>
So, for example, the macro copies the information from the first row, arranges it in a particular manner in the new workbook, creates a folder in a specific directory, saves the new workbook in the new folder. <o:p></o:p>
It then moves to the next row and repeats the process until it hits an empty row.<o:p></o:p>
This all works great! <o:p></o:p>
However, once a row has been saved to it’s new workbook I want to add a hyperlink to a particular cell in the relevant row in the original excel sheet, so I can click on this cell and it’ll open the new workbook with the relevant data. <o:p></o:p>
For the life of me I cannot seem to get this to work. <o:p></o:p>
The really odd thing is I have it working in other bits of code in the same workbook but it just refuses t o work in the current code I’m working on. <o:p></o:p>
<o:p> </o:p>
Where the code works looks like this:<o:p></o:p>
Code:
Dim Co As String<o:p></o:p>
Dim Link As String<o:p></o:p>
Dim Project As String<o:p></o:p>
<o:p> </o:p>
Link = "R:\Dept\General Licensing\General Licensing Summary (DO NOT EDIT)\Sync Licensing Applications\"<o:p></o:p>
Cells(rowno1, 7).Select<o:p></o:p>
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=Link & Co & " - " & Project & ".xlsm", TextToDisplay:="View Report"
<o:p> </o:p>
Where it doesn’t work looks like this:<o:p></o:p>
<o:p> </o:p>
Code:
Dim CompanyName  As String<o:p></o:p>
Dim ProjectTitle As String<o:p></o:p>
Dim TrackTitle As String<o:p></o:p>
Dim Publisher As String<o:p></o:p>
Dim Link As String<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Link = "R:\Dept\General Licensing\General Licensing Summary (DO NOT EDIT)\Sync Licensing Applications\Publisher Sync Requests\"<o:p></o:p>
<o:p> </o:p>
Cells(rowno1, 7).Select<o:p></o:p>
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _<o:p></o:p>
Link & CompanyName & " - " & ProjectTitle & "\" & TrackTitle & " - " & Publisher & ".xlsm", TextToDisplay:=Publisher<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
For some bizarre reason this one doesn’t work. <o:p></o:p>
When I edit the Hyperlink this is what the macro has entered:<o:p></o:p>
<o:p> </o:p>
Code:
[COLOR=black][FONT=Calibri]Publisher%20Sync%20Requests\Test%20Licence%20-%20test%20sync1\Star%20-%20PM%20Productions.xlsm<o:p></o:p>[/FONT][/COLOR]
<o:p> </o:p>
In the first example that works the hyperlink looks like this in the cell:<o:p></o:p>
<o:p> </o:p>
Code:
\\dublin1\DATA\Dept\General Licensing\General Licensing Summary (DO NOT EDIT)\Sync Licensing Applications\Test Licence - test sync1.xlsm
<o:p> </o:p>
<o:p> </o:p>
All the other code, making directories, saving files etc work fine, it’s just this particular macro causing me headaches and I can’t for the life of me figure out what’s wrong. <o:p></o:p>
I’m hoping its something simple and I just can’t see the wood for the trees. <o:p></o:p>
<o:p> </o:p>
Please, Please help!!<o:p></o:p>
It’s driving me crazy at this stage!!<o:p></o:p>
Let me know if you need more info.<o:p></o:p>

Best wishes,

Paul.
 
What if I want the "Publisher" value as the text in the cell, where you've put "View Report"?

thanks,
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Does this method work?

Publisher instead of "View Report"...
Code:
Cells(rowno1, 7).Formula = "=HYPERLINK(" & Link & CompanyName & " - " & ProjectTitle & "\" & _
                           TrackTitle & " - " & Publisher & ".xlsm, " & Publisher & ")"
 
Upvote 0
I got an "application defined or object defined error" :(

I think we're doomed for this never to work......
 
Upvote 0

Forum statistics

Threads
1,216,027
Messages
6,128,375
Members
449,445
Latest member
JJFabEngineering

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top