run macro after userform unloads

P

PMuller

I have a complicated userform contained within a template. Once the userform
is completed and the OK command button is selected the userform merges and
populates.

Within the template I have a series of cross references which I would like
updated once the document populates although I'm not sure how to do this as
the form unloads and then the document populates. Can someone please shed
any light on how I might update fields once the template is has populated?

Basically after the following is completed, then I want do something simple
like a print preview so the cross references are populated. I'm just not
certain how to run another macro after hitting OK.

My OK command is as follows:

Private Sub cmdOK_Click()

ActiveDocument.Bookmarks("Ref").Range.Text = txtRef
ActiveDocument.Bookmarks("Sender").Range.Text = txtSender
ActiveDocument.Bookmarks("SendersTitle").Range.Text = txtSTitle

If OptExistingClient = True Then
ActiveDocument.Bookmarks("ClientStatus").Range.Text = "Paragraph 1"
If OptNewClient = True Then
ActiveDocument.Bookmarks("ClientStatus").Range.Text = "Paragraph 2"

If OptARR_FeeEstimate = True Then InsertARR_FeeEstimate
If OptARR_FeeEstimate = False Then RemoveARR_FeeEstimate
If OptARR_HourlyRates = True Then InsertARR_HourlyRates
If OptARR_HourlyRates = False Then RemoveARR_HourlyRates
If OptOtherServices_FeeEstimate = True Then InsertOS_FeeEstimate
If OptOtherServices_FeeEstimate = False Then RemoveOS_FeeEstimate
If OptOtherServices_HourlyRates = True Then InsertOS_HourlyRates
If OptOtherServices_HourlyRates = False Then RemoveOS_HourlyRates

If CheckBoxOS_PreparationPayroll = True Then InsertOS_PreparationPayroll
If CheckBoxOS_PreparationPayroll = False Then RemoveOS_PreparationPayroll
If CheckBoxOS_ReviewWorkersComp = True Then InsertOS_ReviewWorkersComp
If CheckBoxOS_ReviewWorkersComp = False Then RemoveOS_ReviewWorkersComp
If CheckBoxOS_PreparationMonthlyDebtors = True Then
InsertOS_PreparationMonthlyDebtors
If CheckBoxOS_PreparationMonthlyDebtors = False Then
RemoveOS_PreparationMonthlyDebtors
If CheckBoxOS_PreparationFinancialStatements = True Then
InsertOS_PreparationFinancialStatements
If CheckBoxOS_PreparationFinancialStatements = False Then
RemoveOS_PreparationFinancialStatements
If CheckBoxOS_SuccessionPlanning = True Then InsertOS_SuccessionPlanning
If CheckBoxOS_SuccessionPlanning = False Then RemoveOS_SuccessionPlanning
If CheckBoxOS_BusinessRestructure = True Then InsertOS_BusinessRestructure
If CheckBoxOS_BusinessRestructure = False Then RemoveOS_BusinessRestructure
If CheckBoxOS_AccountingBookkeeping = True Then InsertOS_AccountingBookkeeping
If CheckBoxOS_AccountingBookkeeping = False Then
RemoveOS_AccountingBookkeeping
If CheckBoxOS_GeneralBusiness = True Then InsertOS_GeneralBusiness
If CheckBoxOS_GeneralBusiness = False Then RemoveOS_GeneralBusiness

If OptCOBNE = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text =
"CO Name"
If OptCO = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = "CO
Name"
If OptCOCFIN = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text =
"CO Name CFIN"
If OptCOSEC = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text =
"CO Name SEC Limited"
If OptCOWM = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text =
"CO Name WM"

Selection.GoTo What:=wdGoToBookmark, Name:="Body"

Unload Me

End Sub
 
D

Doug Robbins - Word MVP

You can probably just include a command to update the fields in the
document. If they are all in the body of the document

ActiveDocument.Range.Fields.Update

will do. If there are also fields in the header and footers, it is
necessary to iterate through each of those and update the fields in their
ranges, or a quick and easy way is just to use

With ActiveDocument
.PrintPreview
.ClosePrintPreview
End With


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
J

Jay Freedman

I have a complicated userform contained within a template. Once the userform
is completed and the OK command button is selected the userform merges and
populates.

Within the template I have a series of cross references which I would like
updated once the document populates although I'm not sure how to do this as
the form unloads and then the document populates. Can someone please shed
any light on how I might update fields once the template is has populated?

Basically after the following is completed, then I want do something simple
like a print preview so the cross references are populated. I'm just not
certain how to run another macro after hitting OK.

My OK command is as follows:
[snip unneeded detail]

You must have a macro that declares and shows the userform. (I say
"must" because that's the only way to run a userform in Word.) Maybe
it's Sub AutoNew or Sub Document_New or something else.

When the userform's .Show method is called, control passes to the
userform and its code. When the userform unloads, control returns to
the next line of the macro -- and that's where you can insert the
statements

ActiveWindow.View = wdPrintPreview
ActiveWindow.View = wdPrintView
 
F

Fumei2 via OfficeKB.com

I would like to point out that:

If CheckBoxOS_SuccessionPlanning = True Then InsertOS_SuccessionPlanning
If CheckBoxOS_SuccessionPlanning = False Then RemoveOS_SuccessionPlanning

is two separate instructions, parsed and executed by VBA.

If CheckBoxOS_SuccessionPlanning = True Then
InsertOS_SuccessionPlanning
Else
RemoveOS_SuccessionPlanning
End If

Is ONE instruction. If CheckBoxOS_SuccessionPlanning is not True, then it is
False.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top