PDA

View Full Version : Urgent : help with goto specific page number



forkus2000
03-05-2006, 05:37 AM
Hi guys, this is my fisrst post in this formun, i am new in this area.

My question is :

i have two computers, in one i have a master an the other have a slave, th e master and slave have the same document open, when the master click in an external button send to the slave the page number an the slave display the same page number, sometimes work and other no.

Exist one method called refresh or show like in visual basic to refresh the changes that i made ?

how can i read the exact position relative to my window to send to the slave computer? I need that the two screen show the same image when i click the button!!!


Thanks to all

fumei
03-06-2006, 11:07 PM
The visual display of Word is completely dependent on the printer driver. If your two computers are not using the EXACT same hardware then doing this is difficult.

WHy do you need to do this?

forkus2000
03-08-2006, 04:59 AM
Ok Fumei, but my question its about winword stability.
this is my scenario :

I have a visual basic project with a webbrowser, this webbrowser (activex of visual basic) navigate in my intranet, in this web pager are links to word documents. When the user click the link, the webbrowser show the word document correctly, when i click in the browser goback the browser show me again the web page with the links, but if i see the taskmanager i see the winword.exe still running.

if i have a url link to one word document how can load the word document in a winword but i want to make an instance like createobject("word.document") and when the user click in goback i free and kill winword.

I want to do this because if i work in my intranet for 10 minutes winword increase the memory usage.


do you understand me?

please if you have a code send me

Thank you
Paolo

Killian
03-08-2006, 07:21 AM
Hi there Paolo,

You need to manage the use of Word from your code.
How easy this is depends on what you do, but at it's most simple:

Set an object variable for the Word application at the head of the form module
On form initialize, create a new instance on Word
On form terminate, quit the instance of Word

You may need to do some more work to make sure you are using the correct instance of Word with your code (the user may already have one open when they start)
' the basic userform code
Option Explicit
' with a reference set to the Word
' Object Model in Tools>References
Dim appWd As Word.Application
' or declare as object


Private Sub UserForm_Initialize()
' create a new instance of Word
Set appWd = New Word.Application
' or use
' Set appWd = CreateObject("Word.Application")
' if no reference to the Word Object Model is set

appWd.Visible = False
' navigate to home page
WebBrowser1.Navigate "c:\temp\index.htm"
End Sub


Private Sub UserForm_Terminate()
'quit our instance of Word
appWd.Quit False
End Sub

forkus2000
03-08-2006, 03:35 PM
Thank for your help , but remember i put a webbrowser activex to navigate to the word document.

webbrowser1.navigate2 "c:\hello.doc"

and when i execute

appWd.Quit False

one error show visual basic "runtime error 4605"

please help me

regards Paolo

Killian
03-09-2006, 02:37 AM
Make sure your appWD variable has the correct scope - it needs to be declared outside the routines. (Although this is not the error I would expect if this were the problem.)
I tested this from other Office apps and it works - I don't have VB6 but I wouldn't expect any issues.
If you are doing any Copy/Paste actions in the code, this MSDN article (http://support.microsoft.com/?scid=kb;en-us;896987&spid=2530&sid=36) may be relevant

fumei
03-09-2006, 09:44 AM
Killian, you are opening a html page:
WebBrowser1.Navigate "c:\temp\index.htm" while forkus2000 is opening a Word document:webbrowser1.navigate2 "c:\hello.doc"forkus2000's code will create an instance of Word. Hitting the back button does NOT release that.

You must check for instances of Word and explicitly kill them.

forkus2000, you have this code:
and when i execute

appWd.Quit False 1. when EXACTLY are you trying run this?

2. when EXACTLY are you creating appWord? And why? Your ActiveX control should make an instance because you are explicitly navigating to a Word file.

Somewhere you need to run a function that uses GetObject - not CreateObject - to get the instance of Word, and then kill it. If you get an error with GetObject then of course there IS no instance of Word, and you are OK.

fumei
03-09-2006, 09:46 AM
And by the way...hmmmm, don't you think what you are really asking about has nothing at all:

1. to do with the subject of this thread RE: GoTo page number?

2. to do with your first post,which was about getting the same screen image.

forkus2000
03-10-2006, 04:52 AM
Hi guys..

Continue the problem :

The`problem is sometimes word crash when i want to navigate in some word pages.
To prevent this i want to kill winword every time i finish to use, but i don`y know how to code this.
can somebody send some code in visual basic?
Remember i call word via webbrowser,

Regards Paolo

fumei
03-10-2006, 08:23 AM
Paolo. As I stated last post your posts keep changing. You posted regarding going to a page number and getting the same page on two different computers. You never mentioned anything about Word crashing. Then your post changed to problems with extra instances of Word. You never mentioned anything about Word crashing. Now it is a problem with Word crashing.

Please post describing exactly what the problem is. This has nothing to do with display on two computers, or about going to a specific page number.

Further, as this is (or seems to be) a VB issue, while you still may get an answer here, it may be a good thing to post to a VB forum.

Try the VB forum at Tek-Tips.

As for an answer here....I don't know. I have no idea what "crashing" means for you. Does it means it hangs and Word stays there? If so, how does that fit in with you stating you CAN go back with your browser? So you can go back but Word is still open with the document you went to? If so, then of course there are still instances of winword.exe.

I am very unsure of what exactly is going on.

Killian
03-10-2006, 09:16 AM
Let me clarify the purpose of the code I posted.

On a simple userform (or a form in VB), I've put a webbrowser control
When the form loads, it navigates to index.htm
I create an instance of Word
index.htm has links to some word docs
I can open the docs, go back, open another, etc - my instance of Word is used for them all
When I close the form, I kill my Word session
I gave that part a little tweak, in case it's already deadIf Not appWd Is Nothing Then
appWd.Quit False
End If

I'm sure this is what you asked for at some point. Is it not working?

Re: Word crashing.
Have you tested opening these docs individually in a browser control?
Word crashes for all kinds of reasons - you need to be sure you're dealing with one problem at a time.

fumei
03-10-2006, 07:11 PM
Ah...one problem at a time.....

Killian, is there a qualitative difference between the webbrowser loading a HTML file, and the HTML file linking to a Word doc...and the the web browser control opening a Word doc directly?

Killian
03-11-2006, 05:29 PM
I don't believe so. I'm assuming the brief is to open word docs in a web browser control from a list of links (post 3) but however its called the mechanism will be the same.

forkus2000
03-12-2006, 06:54 AM
Guys this is the code, sometimes word continue stay resident in the task bar, i need every time i press back button kill winword.
Other problem is want to hide all toolbars.



Option Explicit
Dim oDocument As Object
Private mDoc As Word.Document

Private Sub Command1_Click()
On Error Resume Next
KillWinword
web.GoBack
End Sub

Public Sub KillWinword()
Set mDoc = Nothing
' i need help here
End Sub

Private Sub Form_Load()
web.Navigate2 "http://192.168.0.102/teknolaboral/senado"
' this page is a browsing directory whith some word documents to navigate
End Sub

Private Sub Web_NavigateComplete2(ByVal pDisp As Object, _
URL As Variant)
On Error Resume Next
Set mDoc = web.Document

If pDisp Is web.Object Then
InitWord
End If

End Sub
Public Sub InitWord()
Dim strTemp
mDoc.ActiveWindow.View.Type = wdNormalView
mDoc.ActiveWindow.View.ShowAll = False
ActiveWindow.ActivePane.Zooms(wdNormalView).PageFit = wdPageFitBestFit
HideAllToolbars
' not work , winword show a little empty commandbar

End Sub

Sub HideAllToolbars()
Dim i As Integer
i = 1
Application.WindowState = wdWindowStateNormal
If ActiveDocument.AttachedTemplate = "Invoice1.dot" Then
Do
If ActiveDocument.CommandBars(i).Name = "Invoice" Then
ActiveDocument.CommandBars(i).Enabled = True
Else
ActiveDocument.CommandBars(i).Enabled = False
End If
i = i + 1
Loop While i < (ActiveDocument.CommandBars.Count)
CommandBars.AdaptiveMenus = False
End If
End Sub

forkus2000
03-12-2006, 07:06 AM
' this is the problem, i need to kill winword every time i press back button.

and when winword load a document in the webbrowser show a commandbar, and i want hide all commandbars.


Option Explicit
Dim oDocument As Object
Private mDoc As Word.Document

Private Sub Command1_Click()
On Error Resume Next
KillWinword
web.GoBack
End Sub

Public Sub KillWinword()
Set mDoc = Nothing
' i need help here
End Sub

Private Sub Form_Load()
web.Navigate2 "http://192.168.0.102/teknolaboral/senado"
' this page is a browsing directory whith some word documents to navigate
End Sub
Private Sub Web_NavigateComplete2(ByVal pDisp As Object, _
URL As Variant)
On Error Resume Next
Set mDoc = web.Document

If pDisp Is web.Object Then
InitWord
End If

End Sub

Public Sub InitWord()
Dim strTemp
mDoc.ActiveWindow.View.Type = wdNormalView
mDoc.ActiveWindow.View.ShowAll = False
ActiveWindow.ActivePane.Zooms(wdNormalView).PageFit = wdPageFitBestFit
HideAllToolbars
' not work , winword show a little empty commandbar

End Sub

Sub HideAllToolbars()
Dim i As Integer
i = 1
Application.WindowState = wdWindowStateNormal
If ActiveDocument.AttachedTemplate = "Invoice1.dot" Then
Do
If ActiveDocument.CommandBars(i).Name = "Invoice" Then
ActiveDocument.CommandBars(i).Enabled = True
Else
ActiveDocument.CommandBars(i).Enabled = False
End If
i = i + 1
Loop While i < (ActiveDocument.CommandBars.Count)
CommandBars.AdaptiveMenus = False
End If
End Sub

Killian
03-12-2006, 08:27 AM
The problem you have is that you only set a reference to the document, you're not doing anything with the word application.
Try just using mDoc.Parent.Quit to kill the application.

forkus2000
03-12-2006, 09:14 AM
sorry friend but not work!!!!

forkus2000
03-12-2006, 09:17 AM
i don`t know how to reference the application, because the application is called by click in the webbrowser window.

sometimes the application ask me save, discard changes when press Back button.

Can i open the document only for view only, can i disable editing the document?

Please respond Asap

fumei
03-12-2006, 09:34 PM
Can we get some clarity here? Forget about your command bar issue. Please figure out what your problem is - ONE AT A TIME!!!.

1. We talking VB here, not VBA, correct?
2. I assume all your references are in place, since you are using Word libraries here. Correct?
3. Killian states the calling mechanism is the same - whether it is a HTML doc (in a web browser) calling Word, or the web browser calling Word. I accept that. But nonetheless, do they RELEASE Word the same?
4. You state you are using the Back button. That is not what you are doing. You are using a command button on the form - as far as I can tell, NOT on the web control - to make a web.goback instruction.
5. You have oDocument declared, but never use it.
6. Some one please clarify...the form loads. It immediate uses the web browser control to navigate to a page. Again, if the navigation is complete, and this is a HTML page, does - in fact Set mDoc = web.Document actually make an instance of Word? I would think not.

Here is #7:Private Sub Command1_Click()
On Error Resume Next
KillWinword
web.GoBack
End Sub

Public Sub KillWinword()
Set mDoc = Nothing
' i need help here
End SubAs Killian points out you can set it to nothing, but you need to QUIT it! Now if mDoc.Parent.Quit is NOT working, it is simply not good enough to state it is not working. Are you getting an error? if so, what?

Killian
03-13-2006, 03:05 AM
OK, well here's your code tweaked around to get hold of the application after navigating to a word doc, and quitting the application on the Back button. It works OK for me, testing in Excel VBA.
If the code fails, you need to specify which line the error is on, what the error is and some information on the status of the Word application variable as you step through the code.Option Explicit
Dim appWord As Word.Application

Private Sub CommandButton1_Click()
On Error Resume Next
web.GoBack
KillWinword
End Sub

Private Sub Web_NavigateComplete2(ByVal pDisp As Object, _
URL As Variant)
'if navigated to a Word document, get the
'documents APPLICATION
If UCase(Right(pDisp.LocationURL, 3)) = "DOC" Then
Set appWord = web.Document.Parent
InitWord
End If
End Sub

Private Sub InitWord()
With appWord.ActiveWindow
.View.Type = wdNormalView
.View.ShowAll = False
.ActivePane.Zooms(wdNormalView).PageFit = wdPageFitBestFit
End With
End Sub

Private Sub KillWinword()
If Not appWord Is Nothing Then
'quit Word without saving
appWord.Quit False
End If
End Sub

Can i open the document only for view only, can i disable editing the document?I don't think you can do a read-only open via the control but you could set the file attributes to read only. In any case, you can force a quit without saving (as in the code above).
To be honest, if you only want the user to view a document, I would advise against designing an app that opens it for them in Word.

forkus2000
03-13-2006, 05:12 AM
ok guys Thanks for the code
actually work the code.

Thanks for all the people to help me.

fumei
03-14-2006, 12:12 AM
To be honest, if you only want the user to view a document, I would advise against designing an app that opens it for them in Word.Yeah.

forkus2000
03-14-2006, 05:28 AM
I set some word `s documents to read-only , i navigate to this links, i change the document exposed in the browser and when i press goback, winword ask me "this documet has changed, do you want to save"

i want to avoid this dialog message, can i do that?

TonyJollans
03-14-2006, 05:50 AM
I told you in one of your other threads that opening as read-ony wouldn't suppress the message.

I wish I knew more about running Word inside IE - but is that actually what
you are doing? What happens when you navigate to a Word document in your Browser control in your VB Form? Where does Word open up - in the browser control, or independently?

forkus2000
03-14-2006, 10:02 AM
Tony : Winword activex it?s opened inside the webbrowser control.

TonyJollans
03-14-2006, 11:01 AM
I just tried to navigate to a Word document in a Web Browser control and it opened an instance of Word on my computer - not inside the web browser.

What am I doing wrong?

Killian
03-14-2006, 01:50 PM
the IE control behaves like windows explorer when navigating local and mapped paths and you'll get the word app. If you use a url (or a link) it opens the instance of word in the control, (like opening a word doc with IE).
This is why I made an index.htm with links to word docs my example. Although I probably should have explained that point in my post rather than just write the code and expect everyone to read my mind :doh:

TonyJollans
03-14-2006, 03:42 PM
I wish I understood this - I'd like to be able to do it, and not just to address the problem at hand but no matter how I go about it I always get a Word app outside the browser control - and I don't have a Goback button either!

In principle it seems to me that an app running inside a browser is the responsibility of the browser and, although one might expect the browser to either always terminate immediately or, maybe, to give the user a choice, there didn't ought to be any question of a lingering instance. In fact, thinking about it, the browser ought to take responsibility for an app it starts even if that app is outside the browser window.

fumei
03-14-2006, 10:37 PM
This was my whole point in the discussion of WHO (to personify the process....) is responsible for the instance. And I was trying to understand where and when instances are created (and "who" is responsible for them) when the browser control opens an HTML (which may open Doc files)vs an actual Doc.

TonyJollans
03-15-2006, 03:52 AM
And, if there is an already running instance of Word, it seems that it is used - so, just as in automation, it's not blanket-acceptable to close the instance.

I'd still like to know what I have to do to get an active back button.

fumei
03-15-2006, 07:17 PM
The Back instruction is from a commandbutton. The form is making an explicit web.goback instruction via a commandbutton.

forkus2000
03-18-2006, 11:40 AM
Hi guys until this time i have a no solution for my question, can someone help me?

Where exist a vb and a word coder to help me?

i don`t think i am the first guy in the word to need this kind of solution!!!


Paolo

TonyJollans
03-18-2006, 02:59 PM
I'm just too confused to be able to help you here I'm afraid.

I know that Word can be run inside IE (although I don't know exactly how). I know that the containing IE application must impose some constraints on the contained Word application but don't know what all of them may be,

None of this knowledge helps me here. If I understand correctly you have a WebBrowser control on a VB Form and from that you navigate to a Word Document. This then opens in a separate Word instance outside the Browser control - this Word instance may have been specially created or may have already existed. On pressing a separate buttton on the Form you want to execute a GoBack instruction in the Word app (returning control to the WebBrowser) and also to close the Word app.

Maybe I'm just being really thick but there is something about this that doesn't make sense to me.

fumei
03-18-2006, 06:05 PM
Hi guys until this time i have a no solution for my question, can someone help me?Paolo...give us a break here. First of all, your question was about "Goto a specific page number". That I believe has been answered.

Second, you DID make a post stating the code works. I assume this is Killian's last code. Are you saying it is NOT working? If so....SAY SO! You can complain about getting help for
Where exist a vb and a word coder to help me?We ARE trying to help.

I posted a number of questions to you, and you did not answer a single one.
i don`t think i am the first guy in the word to need this kind of solution!!!I don't know. Maybe you are. As Killian suggested, using this to open a Word document is not all that great an idea. Perhaps you may rethink what you are doing.

If not, then please clearly restate the issue, step-by-step. Give us your current code. Give us any error messages you get. Comment things out. Tell us everything you are doing - we can not read minds.

I will tell you flatly that I did some tests, using VB and a web browser control, and making proper references to the instance I could get all instances of Word to properly remove themselves.

forkus2000
03-19-2006, 08:44 AM
Ok guys sorry but now i prepare a project with my problems.

Please check the code and send comments.

Regards Paolo

TonyJollans
03-21-2006, 07:08 AM
I'm way out of my depth here - but the water's nice :)

I don't know how much this will help but after you've navigated to the word document (in openbrowser_Click) you can get a reference to the word application by codingSet appWord = web.Document.ApplicationThere seem to be restrictions on what you can do with it but maybe just having it will help get you going in the right direction.