Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Mouse/cursor Position In Word Document


I'm using Word automation in my VB6 application.
*What i want to do:
-I have several textbox shapes. When i click in one (Postalcode) i am showing a button (is a small vb form, so the word textboxshape keeps focus).
This allready works fine. Only i can't get the form/button to position corectly.
I want it placed right to the active TextBoxshape. The problem is getting the correct screen x y for this to place my form. I can't use api GetCursorPos because this follows the mousecursor and is not reliable. Getting the textbox x y i can do

Code:set Tbox = Appword.selection.ShapeRange
pt.x = scalex( Tbox.left, vbpoints,vbtwips)
pt.y = scaley(tbox.top,vbpoints, vbtwips)

frmPostalCode.show vbmodeless
frmPostalCode.Move pt.x, pt.y

'I probable should allso add the Word window left and top.
pt.x = scalex( Tbox.left + AppWord.left, vbpoints,vbtwips)
pt.y = scaley(tbox.top+AppWord.Top,vbpoints, vbtwips)
Only these x y values aren't correct (to small) probably caused by the word document's position having gray area around , i should then proably get the coordinates of the left top position of the white document leftup corner.

*An alternative solution would be to create a button/picture in word doc itself.
Only more difficult to keep the focus on the active textboxshape. Allso a don't wonna use a command button (try to avoid using the Word build in VBA designer). The above solution with vbform seems better to me.

The result wil be this. Word document is open. User clicks on postal textbox shape, a arrowbutton amerges. User clicks arrowbutton and a dbgrid form popsup and user browses to the destination corresponding and pushes the arrowbutton again, which now fills in the Locationfield next to the postalcodefield/textboxshape.
 





Edited by - lvermeersch on 11/21/2005 11:07:13 PM




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Can I Insert A Word In The Cursor Position In A Word Document
I use this statement in VBA2000:

ActiveDocument.Content.InsertAfter ("USA")

but it alwasy insert at the end.

How can I insert a word in the cursor position?

Word Macro To Take Mouse Cursor Position
I have to mark students diagrams and charts etc submitted in MS Word. I have word macros that will create a callout, transparent, in blue, or a large tick in a transparent text box with no border.
I have to drag these from the position on the page where they appear, to where I want them over the students diagram.
Does anyone know how to make a textbox appear at the position of the mouse cursor on the page, using a macro? A working macro that I can then edit to add ticks etc would be very useful.

Even better if it works on Word versions back to 97.

Peter

Mouse Cursor Position
How to get the position (X and Y) of the mouse pointer of an object (label for example)???

Position Of Mouse Cursor In Text-box
hi all.

just wondered how to find out where the cursor is set in a text-box, how to insert something into the existing text right where the cursor is and manually move the cursor some characters.

example:
i have the following text in a multi line textbox:

hello there
i am a multiline
textbox

now the user sets the cursor () here:

hello there
i am a multiline
textbox

now the user can click on a button and then automatically a some characters (XXZZ) are added right where the cursor is:

hello there
i am aXXZZ multiline
textbox

now last but not least i want the cursor to move 2 characters back:

hello there
i am a XXZZ multiline
textbox

understood?

thx for answers!

j0sh

Rotating Mouse Cursor Position
I'm having issues using the SetCursorPos API on rotating the mouse cursor in a circular motion around a certain point. My code looks ok though. I don't have time to make a sample app since my main projects too big to upload (not to mention I'm leaving work right now), but can anyone provide a solution for me? I'll tackle on it tommorow. Thanks in advance, and rep points will be given out to those who solve my problem.

Manually Position Mouse Cursor??
I want my users to be able to type in an X and a Y coordinate into text boxes and click ok and have the program put the mouse cursor at that exact location. I have the X and Y coordinates, but am not sure what to use to send the cursor there.

Any help is appreciated.

Thanks in advance!!

How Do I Find The Mouse/cursor Position?
I've been scouring the internet looking for the answer but I can't find it. How do I get the coordinates of the cursor on the screen?

Edit: Let me clarify: Anywhere on the screen, not just in the program window. Thanks.

Double Edit:
This is pretty much what I'm looking for but it only shows me the coordinates in the program window:

Code:

Public Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblX.Caption = X
lblY.Caption = Y
lblButton.Caption = Button
End Sub

Setting Mouse Cursor Position
any idea how to set a mouse cursor position in vb6

**situation**
if i go over over 180 pixels from the center of the form the mouse cursor will automatically position itself 360 pixels pass the middle of the screen from the current postion

thanks in advance for helping

note* pls post some code im preety new with vb6*

[VB6] How To Get The Mouse Cursor Position In A Form
I am a newbie on VB and I would like to write a PhotoHunt game in VB6.0. When player click on the image in the VB form, the program should be able to detect the coordinate of the mouse cursor with respect to the image (i.e. with the upper left coner of the image as the origin)

I know there is a function called GetCursorPos to retrieve the mouse cursor's coordinate. But that coordinates is w.r.t. the whole screen. So,
1)is there another function for getting the cursor's coordinate w.r.t. the image in the form? Or
2)are there functions for getting the form's coordinate and the image's coordinate w.r.t the whole screen?

Thx~

Set Mouse Cursor Position Quick Question
ok, i know how to set the mouse cursor , but only ON AN OBJECT. I know how to set the position relative t per se , a form. BUT, how can I set it relative to the screen. If I am getting the cursor position from a screen, I want to be able to set that same position relative to the entire screen, not an object like a form, unless i maximized it or something? but i dont really want to do that.

PLEASE, HELP, appreciate it thanx!

Position Second Form At Mouse Cursor Coordinates
I have a label on my first form.

When I right click on this label, i want a second form to open at the mouse coordinates of where I just right-clicked. So the left/top properties of the second form are right at the mouse cursor.

how can i do this ?

Get Word's Cursor Position
Hi,

I have a form that opens on top of a doc so the user can perform a search. The form is rather minimal, but it still gets in the way sometimes and covers the search hit (selected text in the doc).

I want the form to move out of the user's view. Since the search hit is selected, I could use the insertion point's position on the screen as reference, but I don't know how to do that in VBA or using an API call.

Any help would be highly appreciated.

Regards,

Guillermo

Get The Position Of The Cursor In Word
I want to draw a shape wherever the cursor is located in a document. How do I find out where the cursor is.

 

VB MS Word Template. Cursor Position On Form?
I've created a form to simplify data input (just less clicking all over the place) THe problem is once the form is completed, the cursor/Caret isn't where I want it to be.


How do I get the cursor/caret to be in a specific place in a document once the Form has been completed and the info automatically put into the document? (I've used bookmarks to insert my info into this ms word document).?

Presently the cursor/caret shows up at the end of the document (Where the final Return carrage is). I want it to be at the beginning of the document though.

Any advice?

Position Shape In Word Document
hi,
I am able to overlap jpg picture in word document. Now I am trying to position it over the selected text. How can I do that?
I am using following code and able to position but its not working perfectly.
I am using information(wdHorizontalPositionRelativeToTextBoundary) to get insertion location.

Code:
Dim app As Object
Dim myDocument As Document
Private Sub Command1_Click()
runWord
SelectionFind text1.Text
insertImage

End Sub

Sub runWord()

Set app = CreateObject("Word.Application")
Set myDocument = Documents.Open(FileName:="c:data.doc")
app.Visible = True
myDocument.Paragraphs.LineSpacing = 24

End Sub

Sub insertImage()
setProperty
End Sub

Sub setProperty()
Dim imageName As String
Dim offsetY, offsetX, offsetWidth, offsetHeight As Integer
imageName = "c:circle.jpg"

myDocument.Shapes.AddPicture FileName:=imageName
ActiveDocument.Shapes(1).WrapFormat.Type = wdWrapNone
ActiveDocument.Shapes(1).ZOrder msoSendToBack
ActiveDocument.Shapes(1).ZOrder msoSendBehindText
SelectionFind (mainfrm.text1.Text)
ActiveDocument.ActiveWindow.View.Type = wdPrintView

ScaleMode = 3



x = Selection.Information(wdHorizontalPositionRelativeToTextBoundary)
y = Selection.Information(wdVerticalPositionRelativeToTextBoundary)
ActiveDocument.Shapes(1).Width = TextWidth(Selection.Text) + 4


ActiveDocument.Shapes(1).Left = x + offsetX
ActiveDocument.Shapes(1).Top = y + offsetY
End Sub


Sub SelectionFind(strFind As String)
Dim temp As String
With app.Selection.Find
.Text = strFind
If .Execute = True Then
MsgBox "Text found.", vbOKOnly

End If
End With

End Sub

I am attaching output file. my objective is to take selected text inside circle picture. When I select bigger or smaller text and that will difference in allignment. How can I maintain allignment regardless of text length.

I only want to insert picture over selected text. but search method search all document so if there are some other matches that will make improper operation.. How can I do that?

Thanks

Help! How Can I Position A Form On Top Of A Word Document?
I have a Word document that pops up a userform when certain fields on the Word document are entered. Is there any way to figure out the position of the control on the form so I can position my vb form on top of the control on the Word document, taking into account screen resolution, zooming, scrolling, toolbars, etc...?
I've worked it out except for vertical scrolling and zooming, but it seems like a convaluted way of doing it. Is there an easy way to do this?

Getting Word Under Mouse Cursor
Hello

this question must have been asked before.. but i noticed in easy lingo dictionay it can get the meaning of the word u hover in a matter of seconds.

i dont need the code as much as discussing the technique...
i have searched about the technique and i found one way like this which only works on Rich TextBox and what i need to do is get the closes character to mouse cursor in the rich text using EM_CHARFROMPOS and SendMessage.
This brings to my attention the problem that the cursor might be over a character which is at the middle of the word
e.g
Hello -> user pusts cursor above e and i will get the list of words beginnign with e which is wrong...

but it has an answer which is that i can see that the character i got from sendmessage is inside my word that i am looking for then do some maths to get the position of the letters b4 that character and after so that i can get the whole word.

i have been also told about hooking and subclassing but i dont know what that has to do with what i am thinking about also my way only works on rich textbox.

any one does have an idea about this or anything that can help me understand the technique and would like to share is welcome

Getting Character Position Of String In Word Document
Hi,
The motivation for my question is this:
I intend to introduce tags into a Word document and use them for formatting.
For example, somewhere in the document The following string is inserted:

<b>My bold string</b>

I need to find this string programatically and format it, removing the tags.

I thought I could do it using the Find object and getting the character positions of the tags. I couldn't figure out how to do it. I was dismayed to find out the Find object does not provide the Start and End character positions.
Any ideas?

Thanks, Ron

Find Curser Position On Word Document
Hi

Is there any command that will show me an integer/long value for the curser or scroll bar position in a word document

so that when i find a word in the document i can tell if it before or after a position stored in a variable?

Determining Vertical Position In A Word Document Using Vba
Hello.

I'm wondering how I would determine, using VBA, how far down a page from the top an element on a word document is located?

Here's my situation:

I have a document with three tables. The last (bottom) table is static (always the same size). The top table is fairly static, but the row heights do change slightly depending upon information entered in a userform (which then populates the table).

The middle table is the one I'm interested in. I use a userform to have new rows added to the second table and populate the new row.

I want to limit the size of this middle table so that it does not allow a second page to be created. Currently, I'm using height rule to add the row heights of each row in this table, and then I check to see if the total height is greater than a certain number.

Obviously, this method has some drawbacks. If the top table gets unusually large (which it may in rare occasions), then the middle table may still be to large and thus bump to a second page. Also, in my row height check, I make a big assumption that if a new row was added, it would have the same row height as the last current row in the table. And, the 'certain number' I compare to is a set number, while in reality the total avaialble height of the table will depend on the total height of the first table. I suppose I could add the total height of both tables, and then compare THAT to a 'certain number', but there must be a much simpler way to go about it!

I'd like instead to be able to check the table height by comparing the absolute position of the bottom of this table (from the top of the document) against a predetermined maximum distance from the top.

All help or comments are appreciated!

Thanks,
Corey Dale

How Can I Find The Position Of Bookmark In A Word 2000 Document?
I've been struggling with a particular report for a while now, and hope that the VB community can help me with this problem. I want to find the position of a bookmark or form field in a word document. (I'll explain my situation below)

I have attached a jpg with an example of what I am trying to do.

The report has a header always at the top of the first page. (I can't use a header though because I have several form fields in it, but thats no biggie). Usually, the header + body + footer will fit on a single page and nothing goes wrong. However, when the body causes the footer to go to the next page, I am required to show this footer only on the bottom of the last page of the report (which probably will never be longer than 2 pages, but I don't want to assume that).

Initially I thought this could be done with tables and continuous sections in Word, but I haven't had any luck.

Why do I want to find the position of a form field or bookmark? At the beginning and end of the footer section, I've placed textboxes. (txtBegin and txtEnd). I think that I can add a carriage return until I determine these boxes are no longer on the same page, and then I can delete the last carriage return and this footer will sit perfectly at the bottom of the page.

These are my thoughts for a solution. I'm hoping that someone can help me find a way to determine the line or page the bookmark is located on, but I would be welcome to any suggestions at this point.

Thanks for any help the vb community can provide.
Tyler Dueck
dueck@hadmacker.com

Row Position, Column Position Of Cursor In RichTextBox
I am trying to create a text editor with some enhanced specific features for my application. One of these features which is a MUST is that I need to know which row and column my cursor is on at any given time. Therefore if I use the arrow keys, or click on the RichText Box, I can update the statusbar to tell me which line number (row) and character position within the line I am on.

I am not totally sold on using the rich text box, but the files can be somewhat large, and I need the text to be editable.

Cursor Position Revisited</title> <script Type="text/javascript"> <!-- Function PrintTags() { Var Curr=document.getElementById('vB_Editor_QR_textarea').value; Newval=curr.replace(/[highlight]/gi,'[HIGHLIGHT
I am using SelStart to place my cursor at the end of the text in a text box control. Then using SendKeys{Enter} to position my cursor at the next line.

Once I have the cursor positioned at the next line, i don't want to allow the user to edit the previously entered text. I want to allow only new text from that point forward. How can I do this?

I can't seem to get the exact cursor position once I send the SendKey

Need To Track Text Editer Cursor With Mouse Cursor
Hi All
I am Legally Blind with Macular Degeneration in both eyes and use a dual monitor setup with my App on 1 monitor and use the second monitor as my magnifier XP window. As I scroll my mouse cursor across a line of text, on my magnified window the cursor is stationary in the center of the screen and the text scrolls across the screen with the mouse movement.
I am trying to develop an app that will scroll horizontally over a line of text in any format without any vertical jitter and will give me a line feed and carriage return at the end of the line.
I have written some code that does this, but I cannot figure out how to track the text editing cursor with the mouse cursor. The WinXP Magnifier program I am now using, has this feature and I would like to include it in my app.

Thanks much
Any help will be greatly appreciated
edaziz

 

Opening Word Document From Excel When The Word Document Is Read Only
I'm trying to open a Word document from Excel and have hit a snag. The file I'm trying to access is Read-only and the code stops when the "This file is read-only..." prompt displays. How do I get past this? Here's the code that I have so far (thanks to some help from this forum):

Code:
Sub OpenAndPrint()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim stPathName As String

stPathName = Range("B4").Hyperlinks(1).Address

If Dir(stPathName) <> "" Then
Set wdApp = New Word.Application
wdApp.Visible = True
wdApp.DisplayAlerts = wdAlertsNone 'Tried to turn off the prompt, but it didn't work.
Set wdDoc = wdApp.Documents.Open(stPathName) 'Code stops here and waits for the user to respond to the prompt.
Set wdDoc = Nothing
Set wdApp = Nothing
Else
MsgBox "The file does not exist!", vbInformation
End If

End Sub

Cursor Position
I was making playing around with making screensavers (the best way to learn to program). I was trying to make a trail of shapes behind the mouse(the screensaver will only close with the KeyDown and Click event), but I have a small problem, I don't know how to get the shapes to make a trail. I know how to use the MoveMouse event to get the x and y coordinates of the mouse inside the form, and making one shape stay with the mouse. Does anyone know how I can do this?
I need a way to store the previous locations of the mouse, but if I use a timer, it looks jerky?

Position The Cursor?
I have a piece of code that runs on LostFocus() - but thats neither here nor there.
When I tab out, if the value is a duplicate - a message box appears telling the user, the text box is wiped clean, however the cursor moves on to the next text box (as is his want)
Can I tell the cursor to go back to the other TextBox

Getting Cursor Position
hey all-

i asked this yesterday, but this time it is different. is there a way to get the cursor position on the form, rather than the cursor position on the screen? i want this information so that i can make a crosshair with two lines. i just want the lines to be what the cursor position it. thanks

Set Cursor Position
I just want to know if it's possible to set a starting position
for the cursor!
e.g. i've got a TextBox and want the Cursor to appear first in this TextBox


Please answer me it's a part of an test !
Thanx BH

Cursor Position
ive tried to look al over for this but i cant see it anywhere.

i want the flasing cursor to appear 3 characters in from the left in a string i.e. bob|by <-non flashing cursor
anyone know how, im very interested to find out. thanks in advance, Nell

Cursor Position
I need to find the middle of a picture box and set the cursor in the middle of it when the user click's a previous picturebox.

Basically the user clicks the next arrow(picture box) and the next tab on a tabstrip is displayed. The catch is the new tab's height shortens considerably therefore the next arrow(picture box) on the new tab is higher up the screen than the last.
I wish to place the cursor on this new picture box......

I have been through the "getCursorPos & setCursorPos" with no success.

Can anyone help?

Regards Dazza.

Cursor Position
i wanna to know how i can identify the position for a cursor in a text or roch text ??

for example in Vb when i write text1. ( a list will apear at th position of last Charecter ) how i can do that ?

Cursor Position
How do u find Cirsor position in pixels... id like to move a picture based on the position of the mouse pointer
thx

Cursor Position Et. Al.
Hello all, just realized this is the first post I've posted in a few months. But I digress.

I have several problems.

1) I need to set the cursor position to a specific spot in a text box and I haven't figured out how to do that yet. Any help would be appreciated.

2) Is there a way to save an html file from a rich text box without the html code shown on the page? (i.e. I have saved a richtext box as an html file and I couldn't get the html code itself to save)

Edit:
I figured out the third one...


Thanks in advance,
MikeJ

Cursor Position
If i want to get the actual cursorposition on my screen, which code do i have to use??

Cursor Position
I am having a problem with the cursor position in a text box. I have the following code so far but i need to get the cursor under the "mat" on the second line.

Private Sub mnunew_Click()
a = InputBox("Enter work number(1-9999)")
frmmaz2.Visible = True
frmmaz2.Caption = a
frmmaz2.Text1.Text = "UNO Mat init-z" + vbCrLf + " 0"
End Sub

After running the sub, the cursor goes back to the left of the "UNO". I need it under the "Mat" to accept user input and then tab under the "Init-z". How do I do this?

Thanks

Cursor Position
Hi all,
I have a form with two comboboxes and 5 command buttons.What I want to do is if the cursor is in the two comboboxes and when I click any of the 5 buttons, I want to bring back the cursor the to combobox where it was originally before clicking any of these buttons.How can I

Thks in Advance
Dan

Cursor Position
Hi all,
Its me again. I am having two textboxes and command button. When i click the command button, I want to detect where the cursor came from either from Textbox1 and Textbox2.How can I.When I used Me.ActiveControl.Name it gave me the present control name only.How can I get the previous control name

Dana

Cursor Position
I'd like to know how to get the cursor X coordinates. I have this Image that i would like to be able to move left and right by holding down the mouse button on it and moving the mouse, but only on the X-axis. Thanks in advance.

Cursor Position
I am using SelStart to place my cursor at the end of the text in a text box control. How can I have the cursor positioned at the next line.

Cursor Position
Dear friend.

How can we get the cursor position?
As an example, we want that a listbox on the cursor position, how can we get that position?

THX....

Position Of Cursor!
This time I am just out of my mind.

How can I check the cursor position in a textbox? I have to allow a "-" sign only if the cursor is at the beginning of the number in the testbox and discard the keystroke otherwise.

Any idea anybody?

Cursor Position!!!
Is there any way you can determine the postition of the cursor in a multi-line scrolling RichText box??

I will need this knowledge to make an AutoCompleter for my text editor program!!

Set Cursor Position
Anyone know how to set the cursor position at a certain line in a regular Textbox? For example, if I wanted to move the cursor to the beginning of line 14.

Cursor Position
Hello all,

I need to know how i could read in the mouse cursor position on the screen. I know it could be done with api function but i want to only read it when the cursor is in the picturebox. How do i make it read the edge of the picture box to be 0,0 ?

Please provide assistance........

Cursor Position
Hi Everyone!

How can I tell if the cursor is in this box?

Line (x1, y1)-(x2, y2), , B

Thanks,
Joey O

How To Get The Position Of Cursor
how do i get the position of the cursor inside of a codesense control so that i can add text there?
thanks

Cursor Position
I have a web browser control set up on my form and navigate to a web site. There is a text box on the web site I am viewing which was created with a template, therefore has no ID, TagNames, etc. I need to put some text in this text box. When the web site loads, the cursor is blinking in this text box. How do I get the location of the cursor? My thought process was to use the IHMTLTxtRange to create the text range on this text box and fill it in using the PasteHTML method. But I need to know the cursor location, so I can create my text range. Does anybody know how to obtain the cursor location after the web site loads?

Thanks.

cew657

Cursor Position
I'm validating the textbox. once I save the numeric part of my input using left$(), the cursor moves to the first. Insted I want the cursor to stay after the truncated value.
below is the code. Could anyone help me on this?

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim t3 As String
t1 = Text1.Text

Label1.Caption = KeyCode

If KeyCode &lt;&gt; 8 Then
If (KeyCode &lt; 48) Or (KeyCode &gt; 57) Then
MsgBox "enter a valid number.."
t3 = Right$(t1, 1)
t3 = Replace(t1, t3, "")
Text1.Text = t3
End If

End If

t1 = Text1.Text
If t1 = 0 Then
Text1.Text = ""
MsgBox "enter valid number"
End If
End Sub

ys

Copyright 2005-08 www.BigResource.com, All rights reserved