Consulting

Results 1 to 5 of 5

Thread: Access Hyperlink stops Word Add-in (Access 2013)

  1. #1

    Question Access Hyperlink stops Word Add-in (Access 2013)

    I am creating a table to place the information for the different files that we use at work. The files are both Excel and Word. The table will have hyperlinks to the files so any user can open the file directly. Both the Word and Excel files have a BeforeSave macro that runs as an add-in. The problem is that the BeforeSave event works fine when the Excel files are opened through the Access Hyperlinks but the Word add-in does not work. There are no errors when the save button is pressed, the event is not triggered and it does nothing.
    I had the exact same issue when opening the Word documents through Excel hyperlinks and found the solution through this forum. But I have very little experience with Access vba, so I'm unsure how to adapt the Excel code to work in Access. Below is the code I am using.

    This is the Excel code that I received through this forum (From gmayor) to allow the Word add-in macro to run when opened through an Excel hyperlink (Just need help adapting this to work with Access):
    Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
        Dim wdApp As Object
        Dim wdDoc As Object
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        If Err Then
            Set wdApp = CreateObject("Word.Application")
        End If
        On Error GoTo 0
        wdApp.Visible = True
        wdApp.Run "Register_Event_Handler"
    End Sub
    Here is the code that runs in the Word Add-in:
    Module (mdlEventConnect):
    Option Explicit
    Public EventHandler As New clsEventHandler
     
    Public Sub Register_Event_Handler()
        Set EventHandler.App = Word.Application
    End Sub
     
    Public Sub AutoExec()
        Register_Event_Handler
    End Sub
    Class Module (clsEventHandler):
    Public WithEvents App As Word.Application
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    'Lots of code goes in here
    End Sub
    Thank you very much for the help! -David

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    As there are no references to Excel have you tried the identical code in Access?

  3. #3
    Yeah I tried placing the code below into Access vba with no result. The Word document is opened but then the BeforeSave macro in Word doesn't do anything.
    Private Sub tblProductDocuments_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
        Dim wdApp As Object
        Dim wdDoc As Object
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        If Err Then
            Set wdApp = CreateObject("Word.Application")
        End If
        On Error GoTo 0
        wdApp.Visible = True
        wdApp.Run "Register_Event_Handler"
    End Sub
    Again, I don't know anything about Access code so I am just guessing how to reference the table that the hyperlinks are placed in.

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    You can probably still use the older Access FollowHyperlink VBA as I don't know how the Access 2013 version works.

    https://msdn.microsoft.com/en-us/vba/access-vba/articles/application-followhyperlink-method-acces

    The other point is that VBA can open the actual Document as well as Word, as in

    Dim wApp As Word.Application
    Dim wDoc As Word.Document
    Set wApp = New Word.Application
    Set wDoc = wApp.Documents.Open("C:\Users\A C\Downloads\Word\ExportLetter.docx")

  5. #5
    I was able to get the code to work by making it run with the "click" event on the textbox that the hyperlink is located in. When the Word hyperlink is opened the Word add-in macro now runs.
    Private Sub Document_Location_Click()
        Dim wdApp As Object
        Dim wdDoc As Object
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        If Err Then
            Set wdApp = CreateObject("Word.Application")
        End If
        On Error GoTo 0
        wdApp.Visible = True
        wdApp.Run "Register_Event_Handler"
       
    End Sub
    Now the only problem is that when there is an Excel hyperlink in the text box from a different record set, it starts to open word along with Excel. I'm not sure what I can do about that.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •