Link to home
Start Free TrialLog in
Avatar of jtrapat1
jtrapat1

asked on

Opening Word Document Slow From VB Application

I'm using VB6 against an sql server database.

For some parts of the application, we launch a form which gives the user the ability to view a word document with comments about a particular document.
The time it takes for the word document to launch is very slow.
Is there anything specific that I could check or is there anything in my code that could be written differently to speed up the launching of the word instance?
Here's is the code:
------------------------------------------------------
Private Sub cmdOpenHighlights_Click()
    OpenWord
    Unload Me
    MyWord.Activate
End Sub
-----------------------------------------------------
Private Sub OpenWord()
    Set MyWord = New Application
    MyWord.Documents.Open FileName, , ReadOnly
    MyWord.Visible = True
    MyWord.Width = 600
    MyWord.Height = 440
    MyWord.Left = 0
    MyWord.Top = 0
End Sub
------------------------------------------------------
The word document is stored on a server and there are no problems with the server.
We simply pass the filename and its path on the server.

Thanks in Advance
John
Avatar of RichW
RichW
Flag of United States of America image

How are you declaring your variables?

I just used your code and it works fast enough.

How are you declaring the MyWord variable?  How are you setting FILENAME?  
The READONLY should be vbREADONLY.


Avatar of Mike McCracken
Mike McCracken

Is it always slow or only at times or certain documents?

Network load/traffic, network speed, machine speed, amount of memory, etc can all contribute to fast or slow loading.

That looks to be the same way we open documents some are fast others can be slow.

Do the documents have macros or other features that could slow the loading?

Do the documents load significantly faster in Word directly?

mlmcc
You dont need to open the word document for just viewing it.

You can place a RichTextBox control on your form.
And then use the syntax:

RichTextBox1.LoadFile("C:\Filename.Doc").

RichTextBox offers the similar functionality as the working area of the word document.
had something similar like this before...
It turned out to be much faster to copy the document from the server to the local C: drive and automatically open it from there.  Opening the document directly from the server takes extra time as Word will maintain a temp file in the same folder as the document and that increases network traffic.
In our case, the server was 3000 miles away and it used to take about 3 mins to open the file, now it takes a few seconds.
Avatar of jtrapat1

ASKER

Thanks for all the help.
Am I setting the reference to MyWord in the correct place?
Or should I set it before I call the OpenWord function?
I'm declaring the MyWord variable globally in my main module as:
Public MyWord As Word.Application
---------

I should give you some more details:
I have two command buttons on the form:
An Open Highlights button, which opens the master file as readonly, and a Create Highlights button which does a FileCopy from the server to another directory on the server, allowing the user to make changes.
I'm setting FileName like this:
I use a FileCopy to copy a template to another directory out on the server because I want to save the changes out to that directory.
FileCopy "s:\BPS\GBHighlights.doc", FileName
where FileName is:
FileName = "s:\BPS\" & CurrentYear & "\CGB\" & txtAgency & "Agency.doc"
(whatever agency the user entered into a text field)
I check if the file exists out there; if it does, I show the Open Highlights button; if not, I show the Create Highlights button.
------------------------------------------------

The document always loads slowly- there are no special times.
--------------------------------------------
eosu,
I think you have a good idea:
If I'm only opening the document as vbReadOnly, if I do a FileCopy, it may load quicker.
But, if I do a FileCopy to the users' C:\ drive, say to the C:\Temp directory, should that be a concern?
I mean, after a while of running the app, won't that fill up each persons' temp directory?

----------------------------------------------------
Thanks Again for all the tips.
John
Launch Word to view the file and make your application wait until the Word process closes.  Then copy the file back to the server if changes have been made, and just delete it from the C: drive.

3 questions to answer here...
1. Will more than one person try to edit the file at the same time?
2. How long does it take to open a typical document (roughly).  There are other things to try if it is taking 10 seconds which are not worth bothering about if it takes 10 mins!
3. Is the server remote?  ie located in an office away from the user, and if so what speed is your WAN?

eosu.
eosu,

Yes, it is possible that more than one person may try to edit the file at the same time.
It takes about four to five seconds to open a file directly from the server.
The server is located in an office away from the user.
----------------------------------------------------
What sort of code would you use when you say:
'make your application wait until the Word process closes..'
I want to close down the form that launches word so that the user cannot go back to the form and open multiple word documents OR make another selection from this form.
-------------------------------------------------------
If I want to copy it back to the server, I would just open it as ReadOnly:=False (editable) and FileCopy it back to the server and then use Kill (FileName) to delete the temporary file on the client machine?

Thanks
John
eosu,

Yes, it is possible that more than one person may try to edit the file at the same time.
It takes about four to five seconds to open a file directly from the server.
The server is located in an office away from the user.
----------------------------------------------------
What sort of code would you use when you say:
'make your application wait until the Word process closes..'
I want to close down the form that launches word so that the user cannot go back to the form and open multiple word documents OR make another selection from this form.
-------------------------------------------------------
If I want to copy it back to the server, I would just open it as ReadOnly:=False (editable) and FileCopy it back to the server and then use Kill (FileName) to delete the temporary file on the client machine?

Thanks
John
ASKER CERTIFIED SOLUTION
Avatar of eosu
eosu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If your application is the only one used to open the file, and you connect to a common database, then you can stop others opening the file easily enough by storing the fact that it is already open on a table in the database.

Best of luck.
eosu,

Yes, it is possible that more than one person may try to edit the file at the same time.
It takes about four to five seconds to open a file directly from the server.
The server is located in an office away from the user.
----------------------------------------------------
What sort of code would you use when you say:
'make your application wait until the Word process closes..'
I want to close down the form that launches word so that the user cannot go back to the form and open multiple word documents OR make another selection from this form.
-------------------------------------------------------
If I want to copy it back to the server, I would just open it as ReadOnly:=False (editable) and FileCopy it back to the server and then use Kill (FileName) to delete the temporary file on the client machine?

Thanks
John