Set an excel button to open a url shown in a cell - excel

I would like to create a button to open a url that is shown in a excel cell. the url is generated by the user filling in some information so i'd like to put a button next to the end url which will take the user directly to the page they requested.
could someone please help with this question?
Thanks
Ian

You could use the solution from there Open an html page in default browser with VBA?:
Public Sub ButtonClick()
ThisWorkbook.FollowHyperlink (Range("B2").Value) 'TODO: change cell!
End Sub

Related

Excel Hyperlink function to open a specific page

Could anyone from this group can offer some advice on the problem I'm trying to solve? I was attempting to open a PDF document to a specific page using the Excel Hyperlink function. I tried to solve this mystery but to no avail. Hope someone can provide me their thoughts and ideas.
I tried Google and Youtube but only few were related to my issue and the solution discussed was not working on my situation... or maybe i missed something. This will be a great help for me once the issue is solved. Thank you in advance.
Using a macro enabled workbook you can hi-jack the hyperlink open event but it isn't as dynamic as we would hope it to be. Unfortunately, we cannot cancel any followed hyperlink using Worksheet_FollowHyperlink so we need to find a way around following a direct hyperlink.
We can create a hyperlink which goes nowhere by referencing itself then set the text to display as "Follow Link". Because the cell reference is then in the hyperlink, we can use an offset from that to get the desired address and sub address from the column before it; which then allows us to open the PDF at the desired place.
Unfortunately, the hyperlink if copied down will still reference the original cell, so each link would need to be edited separately. To date I haven't found a way to use the HYPERLINK function successfully.
The hyperlink format in the cell to the left would need to be the full path appended with "#page=" and the relevant page; e.g. C:\links\blah.pdf#page=6
In the worksheet module
Const AcrobatReader = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.TextToDisplay = "Follow Link" Then
Dim Ref As String: Ref = Range(Target.SubAddress).Offset(0, -1).Text
Dim URL() As String: URL = Split(Ref, "#page=")
If UBound(URL) > 0 Then Call OpenPDFtoPage(URL(0), CLng(URL(1)))
End If
End Sub
Function OpenPDFtoPage(FilepathPDF As String, page As Long)
Dim Path As String: Path = AcrobatReader & " /A ""page=" & page & """ " & FilepathPDF
Shell Path, vbNormalFocus
End Function
The AcroRd32.exe path may need updating for specific installations
Maybe having just one "Follow Link" hyperlink where the URL in the cell next to it is more dynamic may allow this to be a bit more useable.

Loading photo from image control to another image control in excel

I am looking to have one image control with a default image set on my worksheet1. On all other worksheets I will have numerous other image controls where people can upload photos. I have a button to delete the photo they would upload but want the default image to show up when clicked. I have the code that's posted below, but its set to load from outside the file.
Private Sub CommandButton1_Click()
Image1.Picture = LoadPicture("C:\Users\jjvernon\Desktop\Upload.jpg")
End Sub
I am hoping all it will take will be to change what's in-between the parentheses.
Thank you,
JJ

How to open a link/url automatically from PowerPoint?

I have a link/url in PPT and I want to open it when the slide appears and without any click on it. Is it possible?
Thank you
Microsoft PowerPoint fires the OnSlideShowPageChange() event for every slide that is shown during the slide show. You can use this facility to call any macro when certain slides are displayed. PowerPoint passes a reference to the SlideShowWindow as parameter to the OnSlideShowPageChange() event.
I assume you have a hyperlink on slide 2. So, copy following code in a VBA modul:
' --- The following macro displays a message when the second slide is shown.
' --- You are asked to open or not to open the link.
' --- The first link on slide 2 is opened when you click the OK button.
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
If SSW.View.CurrentShowPosition = 2 Then
MsgBox "Second slide in the slide show"
result = MsgBox("Open URL?", vbOKCancel)
If result = vbOK Then
ActivePresentation.Slides(2).Hyperlinks(1).Follow
End If
End If
End Sub
Of course you can delete useless lines of code for your needs to step over the message and question.
There is no "easy" way to do this. When you try to achieve something that is non standard in Office, you have to use VBA.
This code line should do the trick in your case :
ActivePresentation.Slides(1).Hyperlinks(1).Follow
If you're not familiar with using VBA in Ppt, I would suggest having a look at guides, there are a bunch of them online :)
I hope this helps !
Have a nice day

How to link to an Excel cell via URL

I've uploaded an Excel sheet to our website, but I want to be able to link to a particular row/cell within that sheet, so when people open it, they are taken to that row/cell straight away. Is this possible?
I tried using www.website.co.uk/test.xlsx#Sheet1!A7 but that doesn't appear to work.
I need to be able to link it from a Google Map comment box into a row/cell so it's leaving it fairly limited.
I would have used Google Sheets, but it's blocked by our IT department unfortunately.
As mentioned, for workbooks that are downloaded, you could try a workbook open event. Also provided users can run macros.
Option Explicit
Private Sub Workbook_Open()
If Evaluate("ISREF('Sheet1'!A1)") Then
With ThisWorkbook.Worksheets("Sheet1")
.Activate
.Range("A7").Activate
End With
End If
End Sub
The code above goes in the pane for ThisWorkbook.

repeat same headers on newly created worksheets in ms excel

I have a already existing excel file with some headers and single worksheet, I want that whenever a user click on add new worksheet button headers should be repeated on the it.Is it possible, if yes please tell be the steps to create one excel like this.
You could use a template, although that's a question for the superuser site.
As a macro answer try this:
Create a new worksheet with only the header on it, Rename this sheet Template.
Go into the Developer tab and insert an ActiveX button, double click it to go into the vba editor (you may need to save your document as a macro enabled document first)
Change the name of your button to btnNewWorkSheet and the caption to something like "Click here for a new worksheet"
Go into the sheets page in the VBA editor and copy this code:
Private Sub btnNewWorkSheet_Click()
Sheets("Template").Copy After:=ActiveSheet
End Sub
Now you can click on the button on any page where it appears to create a copy of the Template page
You can paste the following code to "ThisWorkbook" module:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
If TypeName(Sh) = "Worksheet" Then
Sheet1.Range("A1:K1").Copy Sh.Range("A1")
End If
End Sub
Sheet1 is the name of the single worksheet object, replace A1:K1 with the range of your headers, replace A1 with the desired destination.

Resources