How to access VBA in Word Document from Excel VBA

pg11rahul_m

New Member
Joined
Jan 14, 2015
Messages
14
Hi,

I have a Word macro enabled document with ActiveX controls in it. A user can basically select multiple check boxes or select options in combo boxes on the Word Form. There are certain fields that I want to make sure the user fills before closing the word document. Below piece of code addresses this requirement.

Code:
Option Explicit
Public WithEvents oApp As Word.Application
Private Sub oApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)


'Below code prompts a reminder message when user tries to close the form


Dim response As Integer
response = MsgBox("Reminder: Have you updated Total Number of Objections? ", vbYesNo)
If response = vbYes Then
    Cancel = False
Else
    Cancel = True
End If


End Sub

Now I have an excel VBA tool that creates a word object and using that object reads all the information that the user has filled in the Word form. Once all data is extracted I close the word form using below code:

Code:
wDoc.Close SaveChanges:=False

Problem is when I use above code it pops up the reminder message (1st piece of code) again. I was trying to figure out a way to prevent this. Maybe I can access the VBA code in the word document and assign some values that will prevent this. But I'm not sure how I can do that. Any help will be much appreciated.

Thanks.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,394
Messages
6,119,262
Members
448,880
Latest member
aveternik

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