Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

error 4198 when closing document

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba general
View previous topic :: View next topic  
Author Message
Rinze Smit
Guest





PostPosted: Wed Dec 19, 2007 4:04 pm    Post subject: error 4198 when closing document Reply with quote

Hello,

I'm trying to build a template with some formfield-elements.
I need a combobox with more than 25 items, so I use the formfield-
workaround.

I have a formfield which calls a macro "NaarCombo"

-------------------------------
Sub NaarCombo()
Load frmCombo
frmCombo.Show
Application.ScreenUpdating = True
Documents("organisatieonderdelen").Close
'SaveChanges:=wdDoNotSaveChanges
End Sub
-------------------------------

Then in the initialize I fill the combobox. This part works fine.
However, when I try to close the sourcedocument, I get error 4198.
I think this error occurs because the file is still somehow in use.
But I can't see why.
I've tried to change the location of the code for closing the
document. fx: I placed it in sub "NaarCombo". However, this didn't
work. I still got the same error.

I've also tried copying it to "document_close"
This works, but if there are no other documents open, it also closes
Word....
Another option would be to use an Exceldocument as source, but I think
that will be 'slower'.

Can anyone give me some tips in this?

The code in Userform_intialize::::
----------------------------------------
Private Sub UserForm_Initialize()

cmbOrgOnd.ColumnCount = 1
'Load data into ComboBox
' Deze makro laadt de gegevens uit het bestand
organisatieonderdelen.doc in een keuzelijst van het document.

Dim i As Integer, j As Integer, myitem As Range, m As Long, n As Long

'dan de gegevens vanuit de array in de dropdownbox laden.
'dropdownbox moet altijd de naam "OrgOnd" hebben.

strTargetname = ActiveDocument.Name

Application.ScreenUpdating = False
' Open het bestand met de organisatieonderdelen
Set sourcedoc = Documents.Open(FileName:="G:\SjablonenStart-Dir
\databases\organisatieonderdelen.doc")

' Het aantal rijen ophalen
i = sourcedoc.Tables(1).Rows.Count
' Definieer de array waar de organisatieonderdelen in worden
opgeslagen
Dim MyArray() As Variant
'Laad gegevens uit de tabel in de Array
ReDim MyArray(i)
For n = 1 To i + 1
Set myitem = sourcedoc.Tables(1).Cell(n, 1).Range
myitem.End = myitem.End - 1
MyArray(n - 1) = myitem.Text
Next n
' Sluit het bestand met de organisatieonderdelen

cmbOrgOnd.List() = MyArray()

'I've tried to use several other codefragments before the real
'close-statement'. Nothing worked.
'sourcedoc.Saved = True
'Documents("G:\SjablonenStart-Dir\databases
\organisatieonderdelen.doc (Alleen-lezen)").Close
'sourcedoc.Activate
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
Documents(strTargetname).Activate
End Sub
--------------------------------

Many thanks in advance

Rinze Smit
Revalidatie Friesland
Back to top
Google
Sponsor





PostPosted: Wed Dec 19, 2007 4:04 pm    Post subject: Advertisement

Back to top
David Sisson
Guest





PostPosted: Wed Dec 19, 2007 10:37 pm    Post subject: Re: error 4198 when closing document Reply with quote

It all looks correct.

So when you run this and it errors out, you select debug, the
SourceDoc.Close line is highlighted? And if you press F8, it gives
the same error on the same line?

Grabbing at straws here, but try to define SourceDoc

Dim SourceDoc as Document
Back to top
Rinze Smit
Guest





PostPosted: Thu Dec 20, 2007 7:55 am    Post subject: Re: error 4198 when closing document Reply with quote

On 19 dec, 23:37, David Sisson <Tinbe...@gmail.com> wrote:
Quote:
It all looks correct.

So when you run this and it errors out, you select debug, the
SourceDoc.Close line is highlighted? And if you press F8, it gives
the same error on the same line?

Grabbing at straws here, but try to define SourceDoc

Dim SourceDoc as Document

David,

thanks for your reply,
When debugging, the error does not occur!! So the code runs fine when
using F8.
Sourcedoc was defined. First I defined it within the same sub. Then I
defined it on module level... (cause I moved the 'close' statement).
However.... the result was the same. In debugmode the code runs fine.
Running it 'live': I get error 4198.

Rinze
Back to top
David Sisson
Guest





PostPosted: Thu Dec 20, 2007 5:24 pm    Post subject: Re: error 4198 when closing document Reply with quote

Usually when it runs in the editor, but not at runtime, there is a
timing issue.

You might try

cmbOrgOnd.List() = MyArray()
DoEvents

Or You could add a delay and give Word time to process the userform
array. (I can only assume this is the culprit.)

cmbOrgOnd.List() = MyArray()
Application.OnTime When:=Now + TimeValue("00:00:03")
Back to top
Rinze Smit
Guest





PostPosted: Thu Dec 20, 2007 7:30 pm    Post subject: Re: error 4198 when closing document Reply with quote

Thanks,

I'm gonna try next week.
I'll let you know how it went.
Happy holidyas.

Rinze

On 20 dec, 18:24, David Sisson <Tinbe...@gmail.com> wrote:
Quote:
Usually when it runs in the editor, but not at runtime, there is a
timing issue.

You might try

cmbOrgOnd.List() = MyArray()
DoEvents

Or You could add a delay and give Word time to process the userform
array. (I can only assume this is the culprit.)

cmbOrgOnd.List() = MyArray()
Application.OnTime When:=Now + TimeValue("00:00:03")
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba general All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum