VBA to get file path and active worksheet then create link to it

jackson1990

Board Regular
Joined
Feb 21, 2017
Messages
56
Good morning,

Was looking for some help on this small project. I have macro with code that open up an appointment in outlook, but I am looking to auto generate a link to the current worksheet they are in, in the body of the appointment. That way when the appointment comes up they can simply click the link instead of having to go look for the file. Is there a way to use VBA to get the reference of the file path and current active sheet they are on and create a link to that to put in the body of that appointment?

I was thinking it might be something related to this code I have

Code:
Link = Application.ThisWorkbook.FullName

Which would retrieve the file path of the workbook, but then I would need the active sheet too and then create a link based off of that in the body of the appointment.

Any help or ideas?

Much appreciated everyone!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This is my full code for it so far.

Code:
Sub EmailProp() 
  Dim oApp As Outlook.Application
  Dim oNameSpace As Namespace
  Dim oItem As AppointmentItem
  Dim r As Range
Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
Link = Application.ThisWorkbook.FullName
      
  On Error Resume Next
  ' check if Outlook is running
  Set oApp = GetObject("Outlook.Application")
  If Err <> 0 Then
    'if not running, start it
    Set oApp = CreateObject("Outlook.Application")
  End If
  
  Set oNameSpace = oApp.GetNamespace("MAPI")
  
  Set oItem = oApp.CreateItem(olAppointmentItem)
  
  With oItem
  
    .Subject = Range(Cells(r.Row, r.Column), Cells(r.Row, r.Column)).Offset(-12, -4) + " - " + Worksheets("Template Generator").Range("F16") + " - " + Worksheets("Template Generator").Range("B16")
    .Start = Range(Cells(r.Row, r.Column), Cells(r.Row, r.Column)).Offset(0, -1)
    .Duration = "01:00"
    .Body = Link
    
    .AllDayEvent = True
    .Importance = olImportanceNormal
    
    
    .ReminderSet = True
    .ReminderMinutesBeforeStart = "10"


    
    Select Case 1 ' do you want to display the entry first or save it immediately?
      Case 1
        .Display
      Case 2
        .Save
    End Select
  
  End With
    
  Set oApp = Nothing
  Set oNameSpace = Nothing
  Set oItem = Nothing
     
End Sub
Where this
Code:
Link = Application.ThisWorkbook.FullName
will get the reference for the workbook location and the active sheet they are on.

And this
Code:
    .Body = Link
will be where the link is generated in the body of the appointment that can be clicked on by the user.
 
Upvote 0
I figured out I could do this with .HTMLbody. but i'm struggling to find why my .HTMLbody is not working. It just doesn't display anything in the body when I try it. Any help is appreciated!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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