Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to create hyperlink in Excel Spread sheet when writing data

Status
Not open for further replies.

JohnSk

Technical User
Oct 14, 2008
1
EU
Hi.

I got the following code to add data to my spreadsheet:

filepath="C:\Documents and Settings\got-john-sk\My Documents\@@TEMP\Macro test\Bevakningslista.xls"
Set ApplExcel = CreateObject("Excel.application")
Set wbExcel = ApplExcel.WorkBooks.open(filepath)
Set asheet = wbExcel.Sheets("Sheet1")


MkDir "C:\Documents and Settings\got-john-sk\My Documents\@@TEMP\Macro test\GOT" & file_no_str

asheet.cells(no_of_used_rows,1).value = Empl
asheet.cells(no_of_used_rows,2).value = File_station
asheet.cells(no_of_used_rows,3).value = file_no_str
With asheet
.Hyperlinks.Add Anchor:=.range(no_of_used_rows3),Address:="C:\Documents and Settings\got-john-sk\My Documents\@@TEMP\Macro test\GOT" & file_no_str,TextToDisplay:=file_no_str
end With
asheet.cells(no_of_used_rows,4).value = Shipper_Name_str
asheet.cells(no_of_used_rows,5).value = Consignee
asheet.cells(no_of_used_rows,6).value = Origin
asheet.cells(no_of_used_rows,7).value = Destination
asheet.cells(no_of_used_rows,8).value = delivery_terms
asheet.cells(no_of_used_rows,9).value = CFS
asheet.cells(no_of_used_rows,10).value = ETS
asheet.cells(no_of_used_rows,11).value = ETA
asheet.cells(no_of_used_rows,12).value = Vessel
asheet.cells(no_of_used_rows,13).value = Typ
asheet.cells(no_of_used_rows,17).value = MBL_number
asheet.cells(no_of_used_rows,20).value = "ny upplagd"

wbExcel.save
ApplExcel.Quit

I want the data in cell (no_of_used rows,3) to become a hyperlink to the folder with the same name as the string file_no_str, but trying to rip the code from a recorded excel macro I only get "object error".

Can someone pls assist, or do i need to add a second macro to the excel workbook?
 
Hi,

Here are your choices, from Excel HELP
Create a hyperlink

Create a hyperlink to a new file

Right-click the cell or graphic you want to represent the hyperlink (hyperlink: Colored and underlined text or a graphic that you click to go to a file, a location in a file, a Web page on the World Wide Web, or a Web page on an intranet. Hyperlinks can also go to newsgroups and to Gopher, Telnet, and FTP sites.), and then click Hyperlink on the shortcut menu.
Under Link to on the left side of the dialog box, click Create new document.
Type a name for the new file in the Name of new document box.
To specify a location other than the one shown under Full Path, type the new location in the Name of new document box or click Change and then select the location you want. Click OK.
Under When to edit, click an option to specify whether to open the new file for editing now or later.
To assign a tip to be displayed when you rest the pointer on the hyperlink, click ScreenTip and then type the text you want in the ScreenTip text box. Click OK.

Create a hyperlink to an existing file or Web page

Right-click the text or graphic you want to represent the hyperlink (hyperlink: Colored and underlined text or a graphic that you click to go to a file, a location in a file, a Web page on the World Wide Web, or a Web page on an intranet. Hyperlinks can also go to newsgroups and to Gopher, Telnet, and FTP sites.), and then click Hyperlink on the shortcut menu.
Under Link to on the left side of the dialog box, click Existing File or Web page.
Do one of the following:
To select a file from the current folder, click Current Folder and then click the file you want to link to.

To select the Web page from a list of browsed pages, click Browsed Pages and then click the Web page you want to link to.

To select a file from a list of files you have recently used, click Recent Files and then click the file you want to link to.

If you know the name and location of the file or Web page you want to link to, you can type that information in the Address box.

To select the Web page by opening your browser and searching for the page, click Browse the Web , open the Web page you want to link to, and then switch back to Microsoft Excel without closing your browser.
To assign a tip to be displayed when you rest the pointer on the hyperlink, click ScreenTip and then type the text you want in the ScreenTip text box. Click OK.

Create a hyperlink to a specific location on a Web page

To create a hyperlink (hyperlink: Colored and underlined text or a graphic that you click to go to a file, a location in a file, a Web page on the World Wide Web, or a Web page on an intranet. Hyperlinks can also go to newsgroups and to Gopher, Telnet, and FTP sites.) to a specific location on a Web page, make sure the Web page has a bookmark (bookmark: A location or selection of text in a file that you name for reference purposes. Bookmarks identify a location within your file that you can later refer or link to.) at that location.

In Microsoft Excel, right-click the text or graphic you want to represent the hyperlink, and then click Hyperlink on the shortcut menu.
Under Link to on the left side of the dialog box, click Existing file or Web page.
Do one of the following:
To select a Web page from the current folder, click Current Folder and then click the Web page you want to link to.

To select the Web page from a list of browsed pages, click Browsed Pages and then click the Web page you want to link to.

To select a Web page from a list of files you have recently used, click Recent Files and then click the Web page you want to link to.

If you know the name and location of the Web page you want to link to, you can type that information in the Address box.

To select the Web page by opening your browser and searching for the page, click Browse the Web , open the Web page you want to link to, and then switch back to Excel without closing your browser.

Click Bookmark, and then double-click the bookmark you want.
To assign a tip to be displayed when you rest the pointer on the hyperlink, click ScreenTip, type the text you want in the ScreenTip text box, and then click OK.

Create a hyperlink to a specific location in a workbook

To link to a location in the current workbook or another workbook, you can either define a name (name: A word or string of characters that represents a cell, range of cells, formula, or constant value. Use easy-to-understand names, such as Products, to refer to hard to understand ranges, such as Sales!C20:C30.) for the destination (destination: General term for the name of the element you go to from a hyperlink.) cells or use a cell reference.

To use a name, name the destination cells in the destination workbook.
How?

Select the cell, range of cells, or nonadjacent selections (nonadjacent selection: A selection of two or more cells or ranges that don't touch each other. When plotting nonadjacent selections in a chart, make sure that the combined selections form a rectangular shape.) that you want to name.
Click the Name box at the left end of the formula bar (formula bar: A bar at the top of the Excel window that you use to enter or edit values or formulas in cells or charts. Displays the constant value or formula stored in the active cell.) .


Name box

Type the name for the cells.
Press ENTER.
Note You cannot name a cell while you are changing the contents of the cell.

In the source (source file: The file that contains information that was used to create a linked or embedded object. When you update the information in the source file, you can also update the linked object in the destination file.) workbook, right-click the text or graphic you want to represent the hyperlink (hyperlink: Colored and underlined text or a graphic that you click to go to a file, a location in a file, a Web page on the World Wide Web, or a Web page on an intranet. Hyperlinks can also go to newsgroups and to Gopher, Telnet, and FTP sites.), and then click Hyperlink on the shortcut menu.
Do one of the following:
To link to a location in your current workbook, click Place in this document under Link to.

To link to a location in another workbook, click Existing file or Web page under Link to.

If you chose Existing file or Web page, locate and select the workbook you want to link to, and then click the Bookmark button.
Do one of the following:
In the list under Cell Reference, click the sheet you want to link to, and then type the cell reference in the Type in the cell reference box. Click OK.

In the list under Defined Names, click the name that represents the cells you want to link to. Click OK.

To assign a tip to be displayed when you rest the pointer on the hyperlink, click ScreenTip and then type the text you want in the ScreenTip text box. Click OK.
Create a customized hyperlink by using a worksheet function

Creates a shortcut or jump that opens a document stored on a network server, an intranet (intranet: A network within an organization that uses Internet technologies (such as the HTTP or FTP protocol). By using hyperlinks, you can explore objects, documents, pages, and other destinations on the intranet.), or the Internet. When you click the cell that contains the HYPERLINK function, Microsoft Excel opens the file stored at link_location.

Syntax

HYPERLINK(link_location,friendly_name)

Link_location is the path and file name to the document to be opened as text. Link_location can refer to a place in a document — such as a specific cell or named range in an Excel worksheet or workbook, or to a bookmark in a Microsoft Word document. The path can be to a file stored on a hard disk drive, or the path can be a universal naming convention (UNC) path on a server (in Microsoft Excel for Windows) or a Uniform Resource Locator (URL (Uniform Resource Locator (URL): An address that specifies a protocol (such as HTTP or FTP) and a location of an object, document, World Wide Web page, or other destination on the Internet or an intranet, for example: path on the Internet or an intranet.

Link_location can be a text string enclosed in quotation marks or a cell that contains the link as a text string.

If the jump specified in link_location does not exist or cannot be navigated, an error appears when you click the cell.

Friendly_name is the jump text or numeric value that is displayed in the cell. Friendly_name is displayed in blue and is underlined. If friendly_name is omitted, the cell displays the link_location as the jump text.

Friendly_name can be a value, a text string, a name, or a cell that contains the jump text or value.

If friendly_name returns an error value (for example, #VALUE!), the cell displays the error instead of the jump text.

Remark

To select a cell that contains HYPERLINK, click the cell and hold the mouse button until the cursor becomes a cross , then release the mouse button.

Examples

The following example opens a worksheet named Budget Report.xls that is stored on the Internet at the location named example.microsoft.com/report and displays the text "Click for report":

=HYPERLINK(" report.xls", "Click for report")

The following example creates a hyperlink to cell F10 on the worksheet named Annual in the workbook Budget Report.xls, which is stored on the Internet at the location named example.microsoft.com/report. The cell on the worksheet that contains the hyperlink displays the contents of cell D1 as the jump text:

=HYPERLINK("[ report.xls]Annual!F10", D1)

The following example creates a hyperlink to the range named DeptTotal on the worksheet named First Quarter in the workbook Budget Report.xls, which is stored on the Internet at the location named example.microsoft.com/report. The cell on the worksheet that contains the hyperlink displays the text "Click to see First Quarter Department Total":

=HYPERLINK("[ report.xls]First Quarter!DeptTotal", "Click to see First Quarter Department Total")

To create a hyperlink to a specific location in a Microsoft Word document, you must use a bookmark to define the location you want to jump to in the document. The following example creates a hyperlink to the bookmark named QrtlyProfits in the document named Annual Report.doc located at example.microsoft.com:

=HYPERLINK("[ Report.doc]QrtlyProfits", "Quarterly Profit Report")

In Excel for Windows, the following example displays the contents of cell D5 as the jump text in the cell and opens the file named 1stqtr.xls, which is stored on the server named FINANCE in the Statements share. This example uses a UNC path:

=HYPERLINK("\\FINANCE\Statements\1stqtr.xls", D5)

The following example opens the file 1stqtr.xls in Excel for Windows that is stored in a directory named Finance on drive D, and displays the numeric value stored in cell H10:

=HYPERLINK("D:\FINANCE\1stqtr.xls", H10)

In Excel for Windows, the following example creates a hyperlink to the area named Totals in another (external) workbook, Mybook.xls:

=HYPERLINK("[C:\My Documents\Mybook.xls]Totals")

In Microsoft Excel for the Macintosh, the following example displays "Click here" in the cell and opens the file named First Quarter that is stored in a folder named Budget Reports on the hard drive named Macintosh HD:

=HYPERLINK("Macintosh HD:Budget Reports:First Quarter", "Click here")

You can create hyperlinks within a worksheet to jump from one cell to another cell. For example, if the active worksheet is the sheet named June in the workbook named Budget, the following formula creates a hyperlink to cell E56. The link text itself is the value in cell E56.

=HYPERLINK("[Budget]June!E56", E56)

To jump to a different sheet in the same workbook, change the name of the sheet in the link. In the previous example, to create a link to cell E56 on the September sheet, change the word "June" to "September."

Create a hyperlink to an e-mail address

When you click a hyperlink (hyperlink: Colored and underlined text or a graphic that you click to go to a file, a location in a file, a Web page on the World Wide Web, or a Web page on an intranet. Hyperlinks can also go to newsgroups and to Gopher, Telnet, and FTP sites.) to an e-mail address, your e-mail program automatically starts and creates an e-mail message with the correct address in the To box, provided you have an e-mail program installed.

Right-click the text or graphic you want to represent the hyperlink, and then click Hyperlink on the shortcut menu.
Under Link to on the left side of the dialog box, click E-mail address.
In the E-mail address box, type the e-mail address you want.
In the Subject box, type the subject of the e-mail message.
Note that some Web browsers (Web browser: Software that interprets HTML files, formats them into Web pages, and displays them. A Web browser, such as Microsoft Internet Explorer, can follow hyperlinks, transfer files, and play sound or video files that are embedded in Web pages.) and e-mail programs might not recognize the subject line.

To assign a tip to be displayed when you rest the pointer on the hyperlink, click ScreenTip, type the text you want in the ScreenTip text box, and then click OK.
Tip

You can also create a hyperlink to an e-mail address in a cell by typing the address directly in the cell. For example, type someone@example.com, and the hyperlink is created automatically.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top