Help with creating hyperlink via VBA

F

FrigidDigit

Hi All,

I'm trying to create a hyperlink for each entry in a list of filenames.
Below is the code that I have come up with so far (I know very little about
VBA:))
fname = objFolder.Path & "\" & objFile.Name
Addrs = Workbooks("Subcontractor invoices Overview.xls").Worksheets("Invoice
Listing").Cells(eRow, 8).Address
MyFormula = "=Hyperlink(" & fname & ")"
Workbooks("Subcontractor invoices Overview.xls").Worksheets("Invoice
Listing").Range(Addrs).Value = MyFormula

When I try to run this it gives me a runtime error 1004 Application defined
or object defined error on the last line above.

Any help would be much appreciated.

FD
 
D

Dave Peterson

Shouldn't this:

MyFormula = "=Hyperlink(" & fname & ")"
look more like:

MyFormula = "=Hyperlink(""" & fname & """)"
or
MyFormula = "=Hyperlink(" & chr(34) & fname & Chr(34) & ")"
 
F

FrigidDigit

Dave,

what do the """" do?

FD


Dave Peterson said:
Shouldn't this:

MyFormula = "=Hyperlink(" & fname & ")"
look more like:

MyFormula = "=Hyperlink(""" & fname & """)"
or
MyFormula = "=Hyperlink(" & chr(34) & fname & Chr(34) & ")"
 
T

Tom Ogilvy

It puts in a double quote within a string.

You can see this by examining it from the immediate window:

fname = "Goofy"
? "=Hyperlink(""" & fname & """)"
=Hyperlink("Goofy")


--
Regards,
Tom Ogilvy

FrigidDigit said:
Worked like a bomb!

Could you explain to me wht """ was used?

Thanks again.

FD
 
F

FrigidDigit

Thanks Tom

FD

Tom Ogilvy said:
It puts in a double quote within a string.

You can see this by examining it from the immediate window:

fname = "Goofy"
? "=Hyperlink(""" & fname & """)"
=Hyperlink("Goofy")
 
D

Dave Peterson

Sorry, I thought you saw the quote marks when you looked at the formula in the
cell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top