473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to set focus on Ms word???

4
Hello all, I want vb.net code to set focus or send cursor to ms word. Could you kindly help me?


For example,

Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop

Dim wapp As Word.Application
Dim wdoc As Word.Document
wapp = GetObject(, "Word.Application")
wapp = Nothing
wdoc = wapp.ActiveDocument
wapp.Visible = True

wapp.activedocument.range.text 'if i write like this i will get all text from MS word, but i want to set focus on ms word i want to know vb.net coding to set focus on ms word. if we use text box we just write textbox.focus().

Please help me.

thank very much.
Mar 11 '08 #1
1 2846
Try something like this:

In the beginning of your program inside the class declaration:

Expand|Select|Wrap|Line Numbers
  1. Declare Auto Function FindWindow Lib "USER32.DLL" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
  2.  
  3. Declare Auto Function SetForegroundWindow Lib "USER32.DLL" (ByVal hWnd As IntPtr) As Boolean
  4.  
then in your method:

Expand|Select|Wrap|Line Numbers
  1. Dim wordHandle As IntPtr = FindWindow(vbNullString, "Microsoft Office Word")
  2. If wordHandle = IntPtr.Zero Then
  3.   MsgBox("Oops!  Couldn't find MS Word window!")
  4. Else
  5.     SetForegroundWindow(wordHandle)
  6. End If
  7.  
Mar 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Clive Moore | last post by:
I am trying to grab the focus of a popup window with a word plugin showing a rtf document using the following code. viewerWindow = window.open("6564641.rtf", "test"); viewerWindow.focus(); ...
13
by: theintrepidfox | last post by:
Dear Group I wondered whether you can help me with this. I do have a page that contains a button and an IFrame. The IFrame contains a dummy page that is set to redirect to a word document when...
0
by: Klein | last post by:
I have an application which can load ms word documents and save them. The application has a main form with a file menu, an edit menu and a tool bar. I have a DocumentControl(usercontrol) defined...
3
by: Lore Leuneog | last post by:
Hello Which command do I've to use to set the focus on a control placed on a report in Design-View. Ctrl.SetFocus and Cmd.GoToControl don't work for a report. The aim is to copy the control...
2
by: RASTA | last post by:
hello everbody, does anyone know, its possible to set the focus of a textbox? if i have an textbox with few lines of text, and i refresh the site, the focus of textbox will move to the...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
8
by: Brad Isaacs | last post by:
Good morning friends, I am working with Visual Studio 2005, ASP.NET 2.0 I am working with the Login controls provided my .NET 2.0, trying to make the Login1 control UserName textbox obtain...
3
Wolfling
by: Wolfling | last post by:
I have a small VB6 app that uses an InternetExplorer control to retrieve some information from a website. It uses a polling technique (eg check the website every 60 seconds). My app remains hidden...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.