Userform Modes?? + Chain of events...

M

Martin Dobson

Hi Guys

I've got a weird problem with a Word Template VBA Project in Word 2003. My template is a simply styled Word Document and has certain "tags" within it, such as [title] and [author] these tags are replaced with content from a userform

Here is an explaination of how it works:

When my template is first run it invokes the Document_New() event which opens a main userform with fields to fill in
The userform is a simple enough form broken down into tabs with text boxes and two command buttons, "cancel" and "Finish". The "Finish" button fires an event that goes away looks through the header, body and footer for certain "tag" references like mentioned in the above paragraph and then replaces them with text entered in the userform textbox controls. This all works fine in Word 2000, Word XP and Word 2003

My problem is that I want to add a Progress message in the form of a userform that appears while the replace occurs against the document. I have tried to use <form>.Show vbModeLess to open the Progress form and then fire my function which replaces the document content. When I test it though the code stops at the <form>.Show vbModeless statement everytime, nothing else get's fired and have even tried adding the reference to my function in the Progress forms Userform_Activate() event, this never gets fired

Please help what am I doing wrong?

Thanks in advance

Martin Dobso
Developer, UK
 
P

Peter Hewett

Hi Martin Dobson

Did you investigate using Bookmarks and inserting text into the bookmark? Using this
method if you need more than one occurrence of the text in the document you can use REF
fields.

Here's my reply to another poster who wanted to do the same thing. I hope it's of help:

This is fairly routine. Here's code pulled out of something I wrote last night for a
client!:

<--------------Code in your module----------------->
Private mfrmS As frmStatus ' Declared outside the sub

Public Sub StartWork
' Display status Form, the status Form calls back to
' UpdateTemplates to do the actual work
Set mfrmS = New frmStatus
Load mfrmS
With mfrmS
.Folder = strFolder
.LogFile = mlogFile.File
.Show
End With

' Tidy up the Status form now that we're done with it
Unload mfrmS
Set mfrmS = Nothing
End Sub

Public Sub DoSomeWork()
Static lngCount As Long

' Do something

' Log it to the status form
lngCount = lngCount + 1
mfrmS.AddInfo = "Status line: " & lngCount
End Sub

I'm assuming you'll display the text in a ListBox as it may be easier to identify each
line. So you add the following code to your Form, this assumes that you have a ListBox
control named "lstStatusInfo":

Public Property Let AddInfo(ByVal AddInfo As String)
With lstStatusInfo
.AddItem AddInfo

' Force last item added to be visible
.TopIndex = .ListCount - 1
End With

' Force changes to be shown
Me.Repaint
End Property

You start by calling "StartWork" to load and display the Status form. The Status form
then calls the procedure "DoSomeWork", which does whatever it is you are doing. While
DoSomeWork executes it updates the Status Form using it's AddInfo property:
mfrmS.AddInfo = "Status line: " & lngCount

HTH + Cheers - Peter

Hi Guys!

I've got a weird problem with a Word Template VBA Project in Word 2003. My template is a simply styled Word Document and has certain "tags" within it, such as [title] and [author] these tags are replaced with content from a userform.

Here is an explaination of how it works:-

When my template is first run it invokes the Document_New() event which opens a main userform with fields to fill in.
The userform is a simple enough form broken down into tabs with text boxes and two command buttons, "cancel" and "Finish". The "Finish" button fires an event that goes away looks through the header, body and footer for certain "tag" references like mentioned in the above paragraph and then replaces them with text entered in the userform textbox controls. This all works fine in Word 2000, Word XP and Word 2003.

My problem is that I want to add a Progress message in the form of a userform that appears while the replace occurs against the document. I have tried to use <form>.Show vbModeLess to open the Progress form and then fire my function which replaces the document content. When I test it though the code stops at the <form>.Show vbModeless statement everytime, nothing else get's fired and have even tried adding the reference to my function in the Progress forms Userform_Activate() event, this never gets fired!

Please help what am I doing wrong??

Thanks in advance!

Martin Dobson
Developer, UK

HTH + Cheers - Peter
 

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