Activate Excel Userform from MS Word

MacroEcon1337

Board Regular
Joined
Mar 16, 2017
Messages
64
I want to activate an Excel UserForm, from Word. Ideally the user would click on a word bookmark and a file dialog would appear, asking the user to select the target Excel file. Then, the macro would reference the Target Excel file and open a UserForm.

Note 1: The target excel file will always be open when the user activates it.

Note 2: The activation event on the word side would be clicking a certain bookmark.

Any ideas? I did solve this once but deleted the file and now I can't seem to create it again.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi

o Do you still need help with this?
o The Word code below shows how to determine if a certain bookmark was clicked.


Code:
' regular module


Function OneBM(rng As Range) As Boolean
OneBM = False
If rng.InRange(ActiveDocument.Bookmarks("page21").Range) Then OneBM = True
End Function


'*******************************************

' ThisDocument module
Dim ev As New Class1


Private Sub Document_Open()
Set ev.app = Word.Application
End Sub
'*******************************

' class module named Class1


Public WithEvents app As Word.Application
Private Sub app_windowselectionchange(ByVal sel As Selection)
MsgBox OneBM(sel.Range)
End Sub
'*************************************************************
 
Upvote 0
Worf, thanks for the response. I am seeking something slightly different...What I am looking for is VBA Code to insert, on the MS Word document side, which references an Excel-Based Userform.


Sequence
1. User opens Word Document X, and clicks on a bookmark located inside Word Document X.
2. The "click" event for this bookmark causes a Userform (Located in an Excel-File Module) to be activated.

Note 1: if it is the first time the user has clicked a Word Bookmark, a File Dialog box appears prompting the user to specify a Target Excel File. Word "remembers" this.
Note 2: if the name/location/path for the Target Excel file changes (ie the "remembered" file path is no longer valid), the prompt re-appears and asks the user to re-specify the Excel file.

I understand this is tricky and was not necessarily expecting a full solution. But any ideas are greatly appreciated,

MC

Hi

o Do you still need help with this?
o The Word code below shows how to determine if a certain bookmark was clicked.


Code:
' regular module


Function OneBM(rng As Range) As Boolean
OneBM = False
If rng.InRange(ActiveDocument.Bookmarks("page21").Range) Then OneBM = True
End Function


'*******************************************

' ThisDocument module
Dim ev As New Class1


Private Sub Document_Open()
Set ev.app = Word.Application
End Sub
'*******************************

' class module named Class1


Public WithEvents app As Word.Application
Private Sub app_windowselectionchange(ByVal sel As Selection)
MsgBox OneBM(sel.Range)
End Sub
'*************************************************************
 
Upvote 0
o What bookmark type do you have? See explanation below.
o I am thinking of placing the workbook path as the bookmark displayed text, as Word needs to remember the information. Is this a problem?
o Happy New Year!

[h=2]Types of Bookmarks[/h]The most important thing you need to know when working with bookmarks in Word is that there are two [FONT=Times New Roman, Times-Roman]“types[FONT=Times New Roman, Times-Roman]”[/FONT] of bookmarks – [FONT=Times New Roman, Times-Roman]“[/FONT]placeholder[FONT=Times New Roman, Times-Roman]”[/FONT] bookmarks and [FONT=Times New Roman, Times-Roman]“[/FONT]enclosing[FONT=Times New Roman, Times-Roman]”[/FONT]bookmarks.[/FONT]
Before we proceed, and whenever you work with bookmarks, you should turn on display of bookmarks by going to Tools | Options | View and selecting [FONT=Times New Roman, Times-Roman]“Bookmarks[FONT=Times New Roman, Times-Roman]”[/FONT]. This makes it easier to see what's actually happening.[/FONT]
(1) Placeholder Bookmarks
If you click somewhere in the document and insert a bookmark it will look like a beam I– this is a [FONT=Times New Roman, Times-Roman]“
placeholder[FONT=Times New Roman, Times-Roman]”[/FONT] bookmark.[/FONT]

(2) Enclosing Bookmarks
Now, if you select some text and insert a bookmark it will look like the selected text is enclosed in square brackets ie: [selected text] – this is an [FONT=Times New Roman, Times-Roman]“
enclosing[FONT=Times New Roman, Times-Roman]”[/FONT] bookmark.[/FONT]
 
Upvote 0
Worf, i am away travelling a few days. I will post detailed answer to your followup questions asap. Thank you, apologies for slow response to my own question, and happy NY!

MC


o What bookmark type do you have? See explanation below.
o I am thinking of placing the workbook path as the bookmark displayed text, as Word needs to remember the information. Is this a problem?
o Happy New Year!

Types of Bookmarks

The most important thing you need to know when working with bookmarks in Word is that there are two types of bookmarks – placeholder bookmarks and enclosingbookmarks.
Before we proceed, and whenever you work with bookmarks, you should turn on display of bookmarks by going to Tools | Options | View and selecting Bookmarks. This makes it easier to see what's actually happening.
(1) Placeholder Bookmarks
If you click somewhere in the document and insert a bookmark it will look like a beam I– this is a placeholder bookmark.

(2) Enclosing Bookmarks
Now, if you select some text and insert a bookmark it will look like the selected text is enclosed in square brackets ie: [selected text] – this is an enclosing bookmark.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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