Excel: adding hyperlink in a cell with existing text [duplicate] - excel

Is it possible to create a hyperlink within an Excel cell which only uses a section of the cell text for the clickable link? I.E. would the below table mockup represent something that can be easily built in Excel 2010?
a mock up http://dl.dropbox.com/u/14119404/misc/Microsoft%20Excel%20-%20Book1_2012-04-16_14-24-47.jpg
I know that an entire cell can be made into a hyperlink easily, but not a specific part of the cell as far as I know.
By hyperlink I also refer to either
(a)another cell or,
(b)a web URL.
Thanks

After creating the hyperlink you could format the text in the cell so that only the words of interest are underlined/blue. The hyperlink will still work, but obviously you can still have only one link per cell, and clicking anywhere in the text will trigger the hyperlink.
For example:
Sub Tester()
Dim rng As Range
Set rng = ActiveSheet.Range("A1")
rng.Parent.Hyperlinks.Add Anchor:=rng, Address:="", SubAddress:= _
"Sheet1!A10", TextToDisplay:="this is long text"
With rng.Font
.ColorIndex = xlAutomatic
.Underline = xlUnderlineStyleNone
End With
With rng.Characters(Start:=9, Length:=4).Font
.Underline = xlUnderlineStyleSingle
.Color = -4165632
End With
End Sub

I needed to link to a filename displayed in a cell, so here is what worked for me:
ActiveSheet.Hyperlinks.Add Anchor:=Cells(row, column), Address:=file.Path, TextToDisplay:=file.Path

This isn't possible in Excel. Hyperlinks are associated with entire cells.
If you look at the documentation for the Excel hyperlink object, you can see that it's associated with a Range. If it were possible to associate hyperlinks with a span within the cell, the Hyperlink object would need to have an associated Range and Characters object.

The above one liner was very helpful... since I'm new, I couldn't comment. So here is my variation of the above that takes each row on a worksheet and builds a URL from a value on the row.
CHGRow = 3
Worksheets("Page 1").Select
Cells(CHGRow, 1).Select
Do Until Application.CountA(ActiveCell.EntireRow) = 0
URLVal = "https://our_url_here?some_parameter=" & Cells(CHGRow, cNumber)
URLText = Cells(CHGRow, cNumber)
ActiveSheet.Hyperlinks.Add Anchor:=Cells(CHGRow, cURL), Address:=URLVal, TextToDisplay:=URLText
CHGRow = CHGRow + 1
Cells(CHGRow, 1).Select
Loop

I'd just make your one row into two rows, merge the cells in the columns you need to have it appear to be a single row and when you get to the cell that needs the hyperlink then you put the words on the top cell and the link in the cell below. It will look fine as a non-techy workaround.

Here's a great smoke-and-mirrors solution I've used for creating hyperlinked strings within a larger block of text in an Excel spreadsheet cell. CAUTION -- if there are multiple editors for your worksheet, this is not advisable as hyperlinks can get misaligned with the text in their cells unless you can provide sufficient protection. A means of doing that is described in this procedure though may limit what contributors can do:
In your Excel spreadsheet, assuming you are not trying to protect ALL cells from editing, select all cells in the worksheet, then select Format Cells from the Home ribbon or the right-click popup menu. On the Protection tab, check then uncheck the "Locked" checkbox to ensure all cells are unlocked.
Now select the (first) cell that will contain the link.
Copy (don't cut) the text that you want to appear as a link to the clipboard.
Click anywhere in your spreadsheet (an unused area is best) and insert a text box from the Insert ribbon using either the Shape icon dropdown or the Text icon. Size and shape aren't important yet, just approximate the size of the link text.
Paste the clipboard contents into the text box.
Right click the text box and select Link to add a hyperlink to it, and specify the link target, whether a location in the current document or a URL.
Select the link text and format it how you want your links to appear, e.g. blue, underlined, etc., since inside a text box this apparently does not occur automatically as in a cell.
Right click the text box again and select Format Shape. From the Format Shape panel, perform the following in order to properly fit the shape around the text and eliminate white space and border:
(a) On the Fill & Line panel (1st icon), select the No Line option.
(b) On the Size & Properties panel (3rd icon), set all 4 margins to zero (0.00"), uncheck the "Wrap text in shape" checkbox, and check the "Resize shape to fit text" textbox."
(c) Under Properties, ensure the following are selected:
* Move but don't size with cells
* Locked
* Lock text
If you need the same hyperlink to occur in multiple cells or locations within the same cell (even if targets differ), clone the text box you did all this work on by selecting its (now invisible) border with a right click (warning - a left click will now take you to the link target instead!), copying it to the clipboard, and press Ctrl+V as many times as you need copies.
Right click on the text box (or one of them if you cloned it) and drag it to the cell where you want the link to appear, positioning it directly over the original text that matches your hyperlink, so as to visually cover it up and replace it (the original text serving as a spacer to make room for it). The steps taken in item 8 above should prevent it from covering up or clipping any text or punctuation surrounding the original text.
Select that cell, then from the Format menu on the Home ribbon, select "Lock Cell" to protect its contents from inadvertently changing and misaligning the text box with the corresponding text that its hiding.
Repeat steps 10 & 11 for each additional copy of the linked text box you created. If any of them requires a different link target, simply right click that copy of the text box, select "Edit Link", and update the target.
From the Format menu on the Home ribbon, select "Protect Sheet". Check the box labelled "Protect worksheet and contents of locked cells".
Check all the other boxes in that dialog also (assuming you are not trying to restrict users in any of those ways) except for the following:
* Format cells
* Format columns
* Format rows
* Edit objects
Leave these four checkboxes unchecked so as to protect your linked text boxes from being selected, deleted, moved, or misaligned with their underlying text. (Note: They should already move with their underlying cells if rows or columns are added, removed or resized, but without this protection they can still be impacted if their own row or column is resized.)
If you want to add a password, do so now. When finished, click OK to apply protection. You can selected "Unprotect Sheet" from the Format menu later to perform any necessary editing, but if the link cell(s), column(s) or row(s) are edited or resized, you may need to reposition the link text box(es) over the underlying text if it moved.
Test your hyperlink(s) and also what happens if you try editing the containing cell(s) or resizing the containing column(s) or row(s) to be sure the worksheet is ready for sharing!

Related

Excel Hyperlink- When clicked make target cell always upper left hand corner

I have a very wide excel spreadsheet. It's formatted in such a way that there is specific data on each screen page. I have the first column frozen so I can place hyperlink buttons vertically. These buttons are hyperlinked to each of the formatted pages in the worksheet.
When I click one of the hyperlink buttons I would like the worksheet to scroll so the target cell in the UPPER LEFT corner of the screen.
I have googled and found this VBA code to place in the "thisworkbook" section of the VBA editor.
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
ActiveWindow.ScrollRow = ActiveCell.Row
ActiveWindow.ScrollColumn = ActiveCell.Column
End Sub
This code does not seem to work for me. If I'm at the far left of the screen and press the hyperlink button it scrolls to the target cell until it gets on the active screen. So basically it always ends up somewhere on the Upper right of the screen. However, if I click the hyperlink buttons the require the page to scroll to the left side of the worksheet it does work.
How can I make it so the target cell is ALWAYS in the upper left of screen after I press the hyperlink button?
Also, how do I know the above code is even running? The hyperlinks seem to be doing the same thing with or without it. I just cut and pasted the code into the VBA editor (per google) for thisworkbook. Is that it or do I need to check something so it will be activated?
Thanks in adavance.
There's a way to do that without using VBA. You can just use a normal hyperlink in the spreadsheet, and link it to "Place in This Document". Make sure you pick the correct Sheet and Type the cell reference that you want to go to (I assume this is A1). This will make sure that whenever you click that particular link, it will always go to that particular spot.
Here's how the edit hyperlink would look in an empty spreadsheet.

Change Style of Selection.ColumnDifferences

I created a macro to add a quick access icon to the Excel toolbar to perform the F5, Special, Column differences task.
How do I change the highlight style of that action? Currently it is a sort of greyish white and if there are multiple differences in a column (50+ rows) muliple differences are not easily recognizable.
I tried this modification but the highlight will stay after another cell is selected.
Sub column_difference()
Selection.ColumnDifferences(ActiveCell).Select
Selection.Style = "Bad"
End Sub
"Bad" is the name of a built-in style. If you change the name of the style to "Good" you will get another colour. If you were to create a style called "MyStyle" you could specify the colour yourself.
There is a "Styles" menu on the Home ribbon. On that menu there is a drop-down button called "Cell Styles". At the bottom of the dialog box that opens when you click that button there is a button called "New cell style". In the dialog box behind that button you can create a style of your own and call it "MyStyle". After that you can use the "MyStyle" name in your code. You can save the style with your workbook.
Needless to say, your code will only work in workbooks where MyStyle style exists. On the other hand, a Style is just a collection of specific cell formats. In the style setup dialog box you find a list of all the format properties a style affects. Your interest seems to focus on the cell's fill colour. Therefore, instead of changing the selected cells' Style you could just change their fill colour.
Select any cell and colour it the way you want. Then, with that cell still selected, enter ? ActiveCell.Interior.Color in the VBE's Immediate window. This will give you the number of your chosen colour. Then modify your code using that number.
Sub column_difference()
Selection.ColumnDifferences(ActiveCell).Select
Selection.Interior.Color = 255
End Sub
255 = vbRed. The above code will change the the Selection's fill colour to red but leave the font colour as it was before. The extra line Selection.Font.Color = vbWhite would change that, too. If you created MyStyle with those two properties you could apply both commands with a single, and shorter, line of code. Selection.Style = "Normal" would change everything back to the original, i.e. what that cell's formatting was when the worksheet was first created.

Excel 2010 - Multiple Types of Locks on the Same Sheet

So I'm trying to create an excel sheet that handles a user input/output task (I know that this is a kludge at best and offensive at worst). So I want the user to be able to edit the input cells (and only the input cells), and select (but not edit) the outputs.
Example: Grid A1:C3. A1:A3 are completely locked - unselectable. B1:B3 are selectable and editable. C1:C3 are selectable and uneditable.
Is this possible? My gut is telling me no, but I thought I'd ask anyway.
It is possible using worksheet protection:
In the Format Cells dialog of the cells B1:B3, uncheck the "Protected" checkbox in the last tab (Protection). Then protect the worksheet (right click the worksheet tab at the bottom->Protect Sheet). Once the sheet is protected, the user can only edit those cells that are unprotected.
Regarding the selection of C1:C3 and non-selection of A1:A3 - you can allow/prevent the user from selecting protect cells in the same sheet protection dialog. However, this is a sheet wide setting, so be default you can only fully prevent selecting all protect cells or allow selection of all cells.
If you only want prevent selection of A1:A3 because you don't want the user to see the formula, just check "Hidden" in the Format cells dialog - this way the user does not see the formula.
If you really need to separate between selectable and unselectable, either split across two worksheets - or use a little VBA macro. To do so, open the VBA editor (Alt+F11) and double click your worksheet in the top-left list. In the code window, enter the following code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Me.ProtectContents And Intersect(Target, Range("B1:C3")) Is Nothing Then Range("B1").Select
End Sub
This way, every time a cell outside your required range is selected, B1 is selected instead

Create a hyperlink within an Excel cell?

Is it possible to create a hyperlink within an Excel cell which only uses a section of the cell text for the clickable link? I.E. would the below table mockup represent something that can be easily built in Excel 2010?
a mock up http://dl.dropbox.com/u/14119404/misc/Microsoft%20Excel%20-%20Book1_2012-04-16_14-24-47.jpg
I know that an entire cell can be made into a hyperlink easily, but not a specific part of the cell as far as I know.
By hyperlink I also refer to either
(a)another cell or,
(b)a web URL.
Thanks
After creating the hyperlink you could format the text in the cell so that only the words of interest are underlined/blue. The hyperlink will still work, but obviously you can still have only one link per cell, and clicking anywhere in the text will trigger the hyperlink.
For example:
Sub Tester()
Dim rng As Range
Set rng = ActiveSheet.Range("A1")
rng.Parent.Hyperlinks.Add Anchor:=rng, Address:="", SubAddress:= _
"Sheet1!A10", TextToDisplay:="this is long text"
With rng.Font
.ColorIndex = xlAutomatic
.Underline = xlUnderlineStyleNone
End With
With rng.Characters(Start:=9, Length:=4).Font
.Underline = xlUnderlineStyleSingle
.Color = -4165632
End With
End Sub
I needed to link to a filename displayed in a cell, so here is what worked for me:
ActiveSheet.Hyperlinks.Add Anchor:=Cells(row, column), Address:=file.Path, TextToDisplay:=file.Path
This isn't possible in Excel. Hyperlinks are associated with entire cells.
If you look at the documentation for the Excel hyperlink object, you can see that it's associated with a Range. If it were possible to associate hyperlinks with a span within the cell, the Hyperlink object would need to have an associated Range and Characters object.
The above one liner was very helpful... since I'm new, I couldn't comment. So here is my variation of the above that takes each row on a worksheet and builds a URL from a value on the row.
CHGRow = 3
Worksheets("Page 1").Select
Cells(CHGRow, 1).Select
Do Until Application.CountA(ActiveCell.EntireRow) = 0
URLVal = "https://our_url_here?some_parameter=" & Cells(CHGRow, cNumber)
URLText = Cells(CHGRow, cNumber)
ActiveSheet.Hyperlinks.Add Anchor:=Cells(CHGRow, cURL), Address:=URLVal, TextToDisplay:=URLText
CHGRow = CHGRow + 1
Cells(CHGRow, 1).Select
Loop
I'd just make your one row into two rows, merge the cells in the columns you need to have it appear to be a single row and when you get to the cell that needs the hyperlink then you put the words on the top cell and the link in the cell below. It will look fine as a non-techy workaround.
Here's a great smoke-and-mirrors solution I've used for creating hyperlinked strings within a larger block of text in an Excel spreadsheet cell. CAUTION -- if there are multiple editors for your worksheet, this is not advisable as hyperlinks can get misaligned with the text in their cells unless you can provide sufficient protection. A means of doing that is described in this procedure though may limit what contributors can do:
In your Excel spreadsheet, assuming you are not trying to protect ALL cells from editing, select all cells in the worksheet, then select Format Cells from the Home ribbon or the right-click popup menu. On the Protection tab, check then uncheck the "Locked" checkbox to ensure all cells are unlocked.
Now select the (first) cell that will contain the link.
Copy (don't cut) the text that you want to appear as a link to the clipboard.
Click anywhere in your spreadsheet (an unused area is best) and insert a text box from the Insert ribbon using either the Shape icon dropdown or the Text icon. Size and shape aren't important yet, just approximate the size of the link text.
Paste the clipboard contents into the text box.
Right click the text box and select Link to add a hyperlink to it, and specify the link target, whether a location in the current document or a URL.
Select the link text and format it how you want your links to appear, e.g. blue, underlined, etc., since inside a text box this apparently does not occur automatically as in a cell.
Right click the text box again and select Format Shape. From the Format Shape panel, perform the following in order to properly fit the shape around the text and eliminate white space and border:
(a) On the Fill & Line panel (1st icon), select the No Line option.
(b) On the Size & Properties panel (3rd icon), set all 4 margins to zero (0.00"), uncheck the "Wrap text in shape" checkbox, and check the "Resize shape to fit text" textbox."
(c) Under Properties, ensure the following are selected:
* Move but don't size with cells
* Locked
* Lock text
If you need the same hyperlink to occur in multiple cells or locations within the same cell (even if targets differ), clone the text box you did all this work on by selecting its (now invisible) border with a right click (warning - a left click will now take you to the link target instead!), copying it to the clipboard, and press Ctrl+V as many times as you need copies.
Right click on the text box (or one of them if you cloned it) and drag it to the cell where you want the link to appear, positioning it directly over the original text that matches your hyperlink, so as to visually cover it up and replace it (the original text serving as a spacer to make room for it). The steps taken in item 8 above should prevent it from covering up or clipping any text or punctuation surrounding the original text.
Select that cell, then from the Format menu on the Home ribbon, select "Lock Cell" to protect its contents from inadvertently changing and misaligning the text box with the corresponding text that its hiding.
Repeat steps 10 & 11 for each additional copy of the linked text box you created. If any of them requires a different link target, simply right click that copy of the text box, select "Edit Link", and update the target.
From the Format menu on the Home ribbon, select "Protect Sheet". Check the box labelled "Protect worksheet and contents of locked cells".
Check all the other boxes in that dialog also (assuming you are not trying to restrict users in any of those ways) except for the following:
* Format cells
* Format columns
* Format rows
* Edit objects
Leave these four checkboxes unchecked so as to protect your linked text boxes from being selected, deleted, moved, or misaligned with their underlying text. (Note: They should already move with their underlying cells if rows or columns are added, removed or resized, but without this protection they can still be impacted if their own row or column is resized.)
If you want to add a password, do so now. When finished, click OK to apply protection. You can selected "Unprotect Sheet" from the Format menu later to perform any necessary editing, but if the link cell(s), column(s) or row(s) are edited or resized, you may need to reposition the link text box(es) over the underlying text if it moved.
Test your hyperlink(s) and also what happens if you try editing the containing cell(s) or resizing the containing column(s) or row(s) to be sure the worksheet is ready for sharing!

Insert picture into Excel cell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I'm tying to generate a report with pictures, but I cannot get the pictures into a single cell. I can get the pictures to "float" around my worksheet, but I need to put them into a cell. How can I do this?
You can add the image into a comment.
Right-click cell > Insert Comment > right-click on shaded (grey area) on outside of comment box > Format Comment > Colors and Lines > Fill > Color > Fill Effects > Picture > (Browse to picture) > Click OK
Image will appear on hover over.
Microsoft Office 365 (2019) introduced new things called comments and renamed the old comments as "notes". Therefore in the steps above do New Note instead of Insert Comment. All other steps remain the same and the functionality still exists.
There is also a $20 product for Windows - Excel Image Assistant...
There is some faster way (https://www.youtube.com/watch?v=TSjEMLBAYVc):
Insert image (Ctrl+V) to the excel.
Validate "Picture Tools -> Align -> Snap To Grid" is checked
Resize the image to fit the cell (or number of cells)
Right-click on the image and check "Size and Properties... -> Properties -> Move and size with cells"
just go to google docs and paste this as a formula, where URL is a link to your img
=image("URL", 1)
afterwards, from google docs options, download for excel and you'll have your image on the cell
EDIT
Per comments, you dont need to keep the image URL alive that long, just long enough for the excel to download it. Then it will stay embedded on the file.
Now we can add a picture to Excel directly and easely. Just follow these instructions:
Go to the Insert tab.
Click on the Pictures option (it’s in the illustrations group).
In the ‘Insert Picture’ dialog box, locate the pictures that you
want to insert into a cell in Excel.
Click on the Insert button.
Re-size the picture/image so that it can fit perfectly within the
cell.
Place the picture in the cell. A cool way to do this is to first
press the ALT key and then move the picture with the mouse. It will
snap and arrange itself with the border of the cell as soon it comes
close to it.
If you have multiple images, you can select and insert all the images at once (as shown in step 4).
You can also resize images by selecting it and dragging the edges. In the case of logos or product images, you may want to keep the aspect ratio of the image intact. To keep the aspect ratio intact, use the corners of an image to resize it.
When you place an image within a cell using the steps above, it will not stick with the cell in case you resize, filter, or hide the cells. If you want the image to stick to the cell, you need to lock the image to the cell it’s placed n.
To do this, you need to follow the additional steps as shown below.
Right-click on the picture and select Format Picture.
In the Format Picture pane, select Size & Properties and with the
options in Properties, select ‘Move and size with cells’.
Now you can move cells, filter it, or hide it, and the picture will also move/filter/hide.
NOTE:
This answer was taken from this link: Insert Picture into a Cell in Excel.
While my recommendation is to take advantage of the automation available from Doality.com specifically Picture Manager for Excel
The following vba code should meet your criteria. Good Luck!
This code will insert the image into the chosen cell and will scale it to fit the exact width and height of the cell. For example:
Instructions:
Add a Button Control to your Excel Workbook (click Developer tab, Insert, Active X, Command Button) and then double click on the button in order to get to the VBA Code -->
Sub Button1_Click()
Dim filePathCell As Range
Dim imageLocationCell As Range
Dim filePath As String
Set filePathCell = Application.InputBox(Prompt:= _
"Please select the cell that contains the reference path to your image file", _
Title:="Specify File Path", Type:=8)
Set imageLocationCell = Application.InputBox(Prompt:= _
"Please select the cell where you would like your image to be inserted.", _
Title:="Image Cell", Type:=8)
If filePathCell Is Nothing Then
MsgBox ("Please make a selection for file path")
Exit Sub
Else
If filePathCell.Cells.Count > 1 Then
MsgBox ("Please select only a single cell that contains the file location")
Exit Sub
Else
filePath = Cells(filePathCell.Row, filePathCell.Column).Value
End If
End If
If imageLocationCell Is Nothing Then
MsgBox ("Please make a selection for image location")
Exit Sub
Else
If imageLocationCell.Cells.Count > 1 Then
MsgBox ("Please select only a single cell where you want the image to be populated")
Exit Sub
Else
InsertPic filePath, imageLocationCell
Exit Sub
End If
End If
End Sub
Then create your Insert Method as follows (this can follow the button's code from above):
Private Sub InsertPic(filePath As String, ByVal insertCell As Range)
Dim xlShapes As Shapes
Dim xlPic As Shape
Dim xlWorksheet As Worksheet
If IsEmpty(filePath) Or Len(Dir(filePath)) = 0 Then
MsgBox ("File Path invalid")
Exit Sub
End If
Set xlWorksheet = ActiveSheet
Set xlPic = xlWorksheet.Shapes.AddPicture(filePath, msoFalse, msoCTrue, insertCell.Left, insertCell.Top, insertCell.Width, insertCell.Height)
xlPic.LockAspectRatio = msoCTrue
End Sub
You can do it in a less than a minute with Google Drive (and free, no hassles)
• Bulk Upload all your images on imgur.com
• Copy the Links of all the images together, appended with .jpg. Only imgur lets you do copy all the image links together, do that using the image tab top right.
• Use http://TextMechanic.co to prepend and append each line with this:
Prefix : =image(" AND
Suffix : ", 1)
So that it looks like this =image("URL", 1)
• Copy All
• Paste it in Google Spreadsheet
• Voila!
References :
http://www.labnol.org/internet/images-in-google-spreadsheet/18167/
https://support.google.com/drive/bin/answer.py?hl=en&answer=87037&from=1068225&rd=1

Resources