Selecting Part Of Cell In Word
Hello,
in my application i send a pricelist to word. It's placed in a table. Now i want to select a part of the first cell in the row and set it bold. Is this possible and how would you do it.
For example: new vbcr article1
I want to put "new" in bold.
???
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Selecting A Whole Cell In A Word Table
Hi there.
I'm struggeling with the following:
I have a Word document with 2 columns. It contains 100 rows, which gives a total of 200 cells.
One of the rows are looking something like this:
_______________________________
|________________|______________|
In my code, I'm able to locate/find the correct row I want to do my selection.
I have a bookmark (called "Labelx" where x is the number of the cell) in every cell.
I'm able to select the first cell (that is the cell to the left), and I'm also able to put my cursor in the next cell (the one to the right).
The big challenge is to "mark"/highlight/select the cell to the right.
The purpose is that I want to select this cell and delete all the contents in it.
Can anyone give me some direction?
So far I have this code:
BookM = "Label" & (i+2) 'This selects the bookmark in the row below the row I want to delete
ActiveDocument.Bookmarks(BookM).Range.Select
Selection.MoveUp Unit:wdLine, Count:=1
Selection.EndKey Unit:=wdStory, Extend:= wdExtend
Selection.Delete
This code, selects all the remaining rows in the documents and deletes them. This is my purpose.
But I also want the code to delete the cell to the right in the last row AFTER deleting the remaining rows.
Hope that my explaination is good enough, if not - give me a hint and I will try to improve.....
Selecting Text In A Word Table Cell
This has probably been answered many times before but I can't find the solution. I need to insert some text into a Word table and then change the font without affecting the text that was already in the cell. My code will look something like this:
Code:
Set oWord = CreateObject("Word.Application")
' Create a new Word document based on works_oder.dot template
oWord.application.Documents.Add App.Path & " emplatesworks_order.dot"
oWord.Visible = True
oWord.Activate
With oWord.ActiveDocument.tables(1) ' First table in Word template
.cell(1, 2).range.insertafter "Temp 0001"
.cell(2, 1).range.insertafter " " & cmbCustomers
.cell(2, 2).range.insertafter vbCrLf & txtDrawingNo
.cell(2, 4).range.insertafter vbCrLf & txtWorksOrderNo
.cell(3, 1).range.insertafter " " & txtCustOrderNo
.cell(4, 1).range.insertafter vbCrLf & txtRequiredBy
.cell(4, 2).range.insertafter vbCrLf & txtDescription
End With
I guess I need to select the text I've just added and then apply the font formatting I need, but I can't quite work out the syntax to select just the new text and exclude the original contents of the cell. Thanks!
Move Part Of Cell Value To Adjacent Cell
I’m working on a series of macros to prepare data imported to Excel for analysis. One that I need help with is this:
There is data in some columns that include and identifier and I need to move the identifier to the cell in the next column(new column). I’ve already created a sub that inserts the new column.
Data Sample:
Column headings: “L/C 100 Hz” “L/C 1 kHz” “L/C 40 kHz” etc
Data examples: “0.33 uF” “7.06 uH”
The “F” and the “H” need to be moved to the cell in the adjacent column leaving the cell like: “0.33 u” and “7.06 u”
how can I do this?
Thanks
Insert Cell Format & Get Cell Value Without Selecting Worksheet
Hello
I am trying to tidy up a workbook. I have several macro's, one of them insert a new line with different cell formats in to different worksheets and most of the others get a cell values for creating reports.
The only way I know of inserting / getting a cell value is to select the worksheet and run the macro
Sheets("Works Schedule").Select
' Run code
This way works but is their a way of running the macro with out selecting the worksheet to stop the workbook flickering between each sheet whiles the macro is running
Thanks
Tom
Selecting A Cell Based On Where The Active Cell Is
Firstly. Hello gurus, developers, lurkers and other bobs. It is a pleasure to find this place and meet you all.
Secondly. Here is the problemette that I am looking for assistance on.
I have been given an Excel spreadsheet to maintain and improve. What I am looking for is to be able to copy data from one worksheet to another with the following requirements. The data that I select is in worksheet 1, columns A and C which I then want to copy to worksheet 2. The process will be dependent on where the active cell is in worksheet 1, which could be anywhere within the range D3 to L1000. (I hope this makes sense)
Up until being given this spreadsheet to maintain I have never used any form of VB before. I have tried a multitude of searches here and on a few other sites and the results of those indicted using Range(ActiveCell, ActiveCell.End(xlToLeft)).Select in some way but so far I have been unable to make it function as required so I am open to suggestions.
Regards
Youngnutter
Selecting Part Of A Picture
Dear friends,
I need to select a part of a picture from a picutre box. I have to select a triangular shape picture part from a picture, ofcourse
the three coardinates will be given.
The selected picture should be displayed in another picture box.
And is it posible to select an arc and polygon shapes from a picture box in the similar way?
Kindly suggest any URLs if you know any?
Thanking you.
Selecting Part Of A ListBox's Text
In my listbox, I'm displaying multiple rows of the following [it's the result of a query sent to Oracle]:
ListBox.AddItem rs("city") & (" ") & rs("phone")
When the user clicks on the ListBox, I would like to have just "city" (not "phone") of that particular selected entry displayed on Label1.Caption. How can I do that? Please help. Thanks.
P.S. Label1.Caption = ListBox.Text would display both "city" and "phone" in the caption...I would like to display just the "city".
Selecting A Part Of The Screen That It Outside The Form.
Hey,
How can I let the user mark a part of the screen that is outside the form? I only need the coordinates that the user selected.
I tried to make a new form and let the user put it and resize it, and then to take it's location. The problem is that there is a Minimum size for the form, that is height:405 and width:870, that is much bigger than what i need.
Thanks, and sorry for my bad English.
Selecting Just Part Of A ListBox's Text
In my listbox, I'm displaying multiple rows of the following [it's a result of a query sent to Oracle]:
ListBox.AddItem rs("city") & (" ") & rs("phone")
When the user clicks on the ListBox, I would like to have just "city" (not "phone") of that particular selected entry displayed on Label1.Caption. How can I do that? Please help. Thanks.
P.S. Label1.Caption = ListBox.Text would display both "city" and "phone" in the caption...I would like to display just the "city".
Selecting Part Of A Multi-dimensional Array
Hi!
I would like to do something like this:
Dim MyArray(1 to 6, 1 to 3) as Integer
Dim x As Object
Set x = MyArray(*, 1)
i.e. assign only the first column to x. Is it possible?
A Cell Contains Part Of...
I have various codes in coloum A that refer to a "device type". For example:
IV64029 is a valve because it's got a V, IM64029 would be a Motor because of the M. What I want to do is search through coloum A and decided if it's going to be a Motor or a Vavle and place the answer in coloum B
Is there a way of doing a "Contains"?
ComboBox - Selecting Part Of An Item After Adding AddItem
I add like 6 positions of data from a Recordset to a combobox, with .AddItem
Then I would like to only select a certain part of the string that is added to the combobox to textbox when the user has selected a row in the combobox.
In a flexgrid this can be done by ex. flexgrid.TextMatrix(lngRowSel, 0)
Is it possible in a way to gey part of combobox data?
Thanks in advance
Getting Part Of Cell's Content
Hi, I have a question
I have the cell A1 that contains the next:
=+(-92438)/AO9
and just I want get the value -92438 and store in a variable
how must I do ?
thank you for your help
loparque
Need To Retrieve A Part Of A Cell/string...
OK so our ID Numbers contain letters, numbers, and hyphens. Something like this:
GFT12PBF9-7865AB
GFT129-7866AB
I need to write a formula in Excel to look for the 'PBF' and retrieve that value. Some of the ID numbers do NOT have 'PBF' in them.
Could somebody perhaps provide an example?
Finding A Part Of A Spreadsheets Cell
Can anybody help me?
I have to read a certain part of a cell in a spreadsheet
the content of the cell looks like this:
[name1],subject;[name2],subject;...
I need to know which name was clicked
the coordinates where I clicked are known by
EventInfo.X and EventInfo.Y but I have no idea how to go on
is there a function to go to this coordinates
and then find out where is the next "[" to get the name which was clicked?
Selecting Diffrent Parts Of MS Chart Control And Changeing The Color,font,name Of The Part
Hello all.
I am very happy to get in to VBCITY which is wonderful site giving more more answers to many people and not only that more knowledge and new things.
I am using a MSchart control to chart data from text file. I have tow things here to code.
1. I need interaction between the text data loaded in the text box and graph data ploted on the graph. i.e when i chage data in text it shoud automatically reflect in the graph(2D line) and vice versa.
2. I want to change the color, font, style of different parts using mouse move event and menubar control.
i have tried individual things like chageing title font ,color using dialog control.
give me some help in proceeding further. Any examples ..
Thanks in advance
Nagababu
Need Help Selecting A Specified Cell
I am not a programmer, so bear with me. I'm doing this project for work, and I've pieced together a little Visual Basic knowlege over the past week; but I can't figure out how to move to a specific cell within my program.
Project: I have two worksheets. Sheet1 (in my code below it's called "CPForm") is an empty form. Basically, it contains two key pieces of info: 1. Down the rows (starting at A13, then A16... every third row) will go employee names; 2. Across the columns will go the days of the week in the format of (m/d... 5/9--> 7 columns total). Sheet2(called "DownLoad") is an exported Sheet from Quickbooks. In it are 3 columns: 1. Date; 2. Employee; 3. Hours worked for that day. Every line contains individual employee's hours for the day, and it continues for a 1 week period. I want to create a program that will, at the press of a button, copy each employee's name over to "CPForm", and then place the number of hours work in the correct cell in the table.
Problem: I have figured out most of it, but I can not figue out how to paste the hours in the correct cell on the CPForm.
Here is the code I've gotten so far:
Code:
Dim LastEmployee As String
Dim Hours As Single
Dim Day As Date
Sheets("DownLoad").Select
Range("A1").Select
Do Until x = 5
Do Until ActiveCell <> "" 'cycling down one line to next name
ActiveCell.Offset(1, 0).Range("A1").Select
x = x + 1
Loop
LastEmployee = ActiveCell 'putting the name in this variable
ActiveCell.Offset(0, -1).Range("A1").Select 'moves active cell to copy date to a variable
Day = ActiveCell
ActiveCell.Offset(0, 2).Range("A1").Select 'moves to put hours worked into a variable
Hours = ActiveCell
Sheets("CPForm").Select
Range("A13").Select
Do Until ActiveCell = "" Or ActiveCell = LastEmployee 'First name will go in A13.. this will cycle down to first open space
ActiveCell.Offset(3, 0).Range("A1").Select
Loop
ActiveCell = LastEmployee 'Puts the employee name in proper place
'???????????
'I can't figure out how to index over to the correct date column
'and place the hours
End Sub
All help is appreciated
Excel: Setting The Colour Of Part Of A String In A Cell
Hi,
I am doing some checking of strings in Excel. Each cell contrains a string, which I check for various things. If I find something wrong, I set the background colour of that cell to show there is an error.
I'd like to go one step further and actually highlight the part of the string that is incorrect by making it bold, or changing the text colour, or whatever, but it isn't clear to me how I'd go about doing this.
It is possible to change part of the string colour by using the GUI in Excel, so I'm assuming that there must be a way to do it from VB.
Can anyone shed some light on this please?
Thanks,
Matt.
Selecting A Excel Cell From Vb6
How to read data from Excel. Make sure you reference MS Excel Object Library 8.0 or 9.0 in VB.
VB Code:
Private Sub Command1_Click()Dim row As IntegerDim col As IntegerDim row_end As IntegerDim col_end As IntegerDim dblArray() As Double Dim objExcel As Excel.Application On Error Resume Next ' grab Excel if open Set objExcel = GetObject(",Excel.Application") ' if error - not open If Err.Number <> 0 Then ' open it Set objExcel = CreateObject("Excel.Application") End If Err.Clear On Error GoTo 0 ' make it visible objExcel.Visible = True ' open normal objExcel.WindowState = xlNormal ' open file objExcel.Workbooks.Open FileName:="C:Book5.xls", ReadOnly:=True ' run macro - not used here 'objExcel.Run "Macro1" ' set up aray to hold values read from Excel ReDim dblArray(1 To 200) ' select a column objExcel.Range("F1").Select ' get max rows row_end = ActiveCell.End(xlDown).Rows.row ' get max columns - not used here 'col_end = ActiveCell.End(xlToRight).Columns.Column ' to grab one cell - not used here 'strMyVar = objExcel.Cells(1, 2) row = 1 col = 6 ' colume F ' loop from row 1 to row_end, column 6 Do Until row > row_end dblArray(row) = objExcel.Cells(row, col) row = row + 1 Loop ' cut array to proper size ReDim Preserve dblArray(1 To row - 1) ' show grabbed values For row = 1 To UBound(dblArray) Debug.Print dblArray(row) Next row ' close workbook - no save objExcel.ActiveWorkbook.Close SaveChanges:=False ' close Excel objExcel.Quit ' clean up Set objExcel = Nothing ' close form Unload MeEnd Sub
Selecting A Certain Cell In Excel
Hi all,
I am working on a project that is using the VB in Excel. I am trying to figure out how to select a certain cell. Basically, I have a column of numbers and these numbers start at 21 then go down to about 3 and then climb back to 21. They are in one column and consist of 4,120 rows. I have an inputted value, say 13, I need to search though the column of numbers and select the first cell that is just before the cell that is <= 13. Then I need to use that row number to identify where the data should start being used for calculation i.e. delete all data above that row indicator. An suggestions would be greatly appreciatted.
Continuoulsy Selecting A Cell In Column B
Hi,
I'm running a loop which, at the end of each row, offsets back to the corresponding cell value in column B. Each row in column B contains a name which I then enter in a message box to prompt the user.
I can write code to select a name in a specific cell, such as B2, B3 etc but i'm unsure how to write the code to continuously know to select the value in column B of a particular row.
A section of my code looks like...
Ans = Msgbox Sheets("Records").range("B2").column
I'm stuck at the moment and any help would be greatly appreciated. Thanks.
Selecting A Range {until Empty Cell}
Hi
I'm trying to write code that will select a range of cells (in column A) but will stop selecting once an empty cell is detected.
I'm not sure if this code should include a do-until loop?
I would greatly appreciate any help.
Thanks
Selecting Cell Range By Clicking It
Let's say I'm making a chart. At some point I'm asked for the range of data to use. I can either type in a cell range, e.g. "=Sheet1!$A$5:$B$10", or I can click that little icon to the right of the text box and then simply click on the cell range I want. Easy peasy!
I want my macro to do exactly this. I want my user to start running the macro, and be asked in a dialog box for a cell reference, at which point they can just click on the cell they want to use (which can be on a different sheet).
Can this be done, and if so, could someone point me in the right direction? Thanks a lot,
Selecting A Cell Thats Not On The Active Workbook
i have the following code:
sourceSpreadsheet.Sheets(1).Range("A1").Select
where sourceSpreadsheet is my workbook object.
if the sourceSpreadsheet is the active workbook, then the code works.
however if another workbook is active i get the following error:
'select method of range class failed'
why is this??
kevin
Selecting A Cell W/ Pointer B4 Starting Sub
Hey fellas,
I created a macro that converts figures with "." as the comma to "," as the comma.
However I don't know how to add something in my sub that displays a msgbox saying "Select the starting cell"
then my sub runs, converts all figures in the same column, then change columns until the end.....
any ideas ?
Selecting Text In A Datagrid Cell
I have a datagrid with (suprise) so data in it. Currently when I single click a cell to begin editing it the entire contents of the cell become highlighted. Is there any way to move the select point to the end of that cell's contents by default when I enter the cell to edit it?
Thanks in advance. =)
Selecting A Cell Through Code With MSHFlexgrid
Hi all.
I'm trying to force selection (through code) of the first row on a MSHFlexgrid and I can't seem to figure out how!
Just in case, Highlight property of the grid is set to "Never" and FocusRect to "Heavy".
Thanks!
Alain
MS Excel - Selecting A Range Using The Last Cell
Hi! Can you help with this problem... it may seem really simple, but I'm new to VB so it's proving to be a little tricky (for me!). Basically the problem is this; using code I've written a VB macro that will present data in a more "visually friendly" format. This is done in Excel. The only thing I'm having problems with is border style. The thing is the macro is to be used on many different sources of data and there will never always be the same number of records (rows) in the spreadsheet each time. Therefore, what I'm trying to do is select all of the cells up to and including the last cell and then format the cells so that they have a border. At the moment I've had to define a range and then afterwards I manually delete the excess cells. Is this possible?
If you can help, I'd be very grateful... not to mention relieved in not having to manually delete cells I don't need.
Thanks.
Set CellPicture In MSFlexgrid Without Selecting The Cell
Hello experts!
I've been able to set images/pictures in MSFlexgrid's Cellpicture using the sample code posted here at Tek-tips. But is it possible to set pictures without selecting the cell, something like TextMatrix(0, nCol), just specify the row and column. Or maybe I'm using the CellPicture syntax in a wrong way.
Any ideas would be a great help.
Thanks!!!
Selecting Top (bottom) Left (right) Cell Of Any Range W/o Using .end()
Hi guys,
I have a range consisting of at least one cell (no MultiAreaRange), and now I want to select one of the edge-cells, let's say the top left cell. How can I do that without using the .end()-thing. I was thinking about a solution using the range.address, but I am not getting anywhere...
But as I know you guys, you'll present me a solution in no time
Thanks in Advance!
DATAGRID Selecting Rows And Changing Value Of A Cell
Hello all. Well, my application is comming along quickly, with just a few quirks here and there, this is another.
I have a DBGrid control on my form, the DBGrid is connected to my database, and I want to be able to update a value of a cell that is in the selected row. The selected row will have the current system date entered into a date cell of the selected row. My problem is; should I use check boxes to select the rows that are to be updated, or just have the user select the row itself? my concern is if the user changes thier mind, and dosn't want to select that row. I've read about using a for loop to do this, but I can't seem to make it work:
Code:
Private Sub dbGridReturnDwg_Click()
intCount = dbGridReturnDwg.SelBookmarks.Count - 1
ReDim ArrSelBK(intCount)
For i = 0 To intCount
ArrSelBK(i) = dbGridReturnDwg.SelBookmarks(i)
If Rs.Fields("issuane.return_date") = "" Then
newNumIssued = Rs.Fields("issuance.num_issued")
newNumIssued = newNumIssued - 1 'subtracts 1 from the number of times this drawing has been issued
Rs.Fields("issuance.return_date") = TodayDate
Rs.Fields("issuance.num_issued") = newNumIssued
Else 'if the date field is not empty, the drawing must have already been returned
MsgBox "The drawing has already been returned!"
dbGridReturnDwg.SelBookmarks.Remove (i) 'this statement may not be needed
End If
Next i
End Sub
Something tells me I need to add the index (i) to the Rs statement i.e.
Code:
Rs.Fields(i,"issuance.return.date") = TodayDate
Selecting Entire Row In Datagrid Regardless Of Cell Clicked
Hey everyone, I've got a datagrid that displays information from a database table (tblCustHistory). What I want to happen is that when the user clicks on a particular row (using the gray box located at the left), and then clicks on a command button (cmdViewHistory), I want to take each of those rows and populate some text boxes at the top of the form. Right now, if the user clicks on the gray box at the left of the row in the datagrid, the whole row is highlighted and when they click the cmdViewHistory button, everything works exactly as it should (the text boxes display the correct information and the database queries based on that row work perfectly). However, if the user clicks a "cell" in the row (and not the gray box to the left of the row), then clicks the command button, I get a "subscript out of range" error. I can only assume this is because one of the fields in the datagrid gets parsed and, unless the who row is sent, it creates an error.
Does anyone know how I can set the datagrid so that if a user clicks on ANY cell in a specific row that the whole row is selected automatically? I know that users aren't always going to click the gray box and this is the only way I know of to get all of the information from that row. Unless I can just record the row number and then, in the command button code, do some kind of select statement on the datagrid?? But that seems like twice to work if I can just get the datagrid to select entire rows.
Anyone have any idea's????
Thanks in advance if you can help.
DTFan
Selecting A Particular Word From A Word Document (.doc) Through Visual Basic 6
I am a developer using Visual Basic 6. One of my program accepts some values through text boxes and then creates a Word document. The text boxes are optional, and the created Word document contains only non-empty values along with appropriate labels. I am able to apply styles (bold and underline) to entire paragraphs. But the user wants me to apply bold formatting only to values entered by him and not to the labels which describe those values. Please help me.
Thank You.
Lalit Kumar Barik
India
Avoiding Re-selecting A Cell After A Form Button Is Pushed
I am working with VBA and Excel 2007 on MS Vista.
I have a form with buttons which execute macros.
If I am on a cell (selected) in the excel spreadsheet and then click a button on the form, I must re-click the cell in spreadsheet after the macro has executed in order to continue typing in that cell.
Is there a way to avoid this re-click?
Thanks,
JoeK
Edit by Moderator:
Please post Excel questions, in the Excel forum.
Thank you.
Selecting And Passing Cell Data To A String With Concatenation
Hi,
I'm stuck on a solution for taking cell content and passing it into a string with concatenation.
For example, I'm trying to take data from cells D12 and F12, D13 and F13, D14 and F14 etc. moving down the rows until I reach an empty cell in column D. With the data from these cells I want to pass it to a string with concatenation.
So not sure how to select the cells and then define the content of the cells in the string.
Thanks in advance for any help offered.
Neil
Finding A String In A Column And Selecting The Contents In The Cell Beside The Found Item
Hi, I'm trying to put code in a form a form where if the user enters a string ie: 1989/12345 in textbox1 the code would look for the same string in a column 1 and select the text in the corresponding column 2 and input it into textbox2. (this should be done as soon as the data in textbox 1 is entered) I'm not sure if it is possible but if so any assistance would be greatfully appreciated.
Opening Excel, Selecting Book / Sheet - Read/write Data To/from Specific Cell Usinf WIN 3A
Please can someone inform me how to do the following using Win32 API functionds onlyl;
1) open excel
2) open a named bookbook and select specific sheet
3) read or write an entry into or out of a specific cell;
I have opend other programs before from a VB6 environment using shell execute statement, however in this problem I am not using VB6, rather a prorietary programming language that allows me to have access to WIN 32 API functions - so my problem has to be solved using these functions only.
Any one's help on this probelm is greatly appreciated.
Regards
adam
Extract Bookmarks Value From Word.doc (part 3)
Hi RobDog888,
Thank you for your speedy response! ButI still get the same error.
1) How to iterate through the collection?
Label1.caption =””
For i = 0 to 41
Labe1.caption = Label1.caption ^ w.Bookmarks(i).Range.Text ^ chr(13)
Next i
The “for loop” does not work for w.Bookmark(i).Range.Text -> because Bookmarks is an object (or collection)?
Perhaps something like the following (I think)??
Dim cntrlItem as ?? (control, index…etc)
For each cntrItem IN ?? (collection, ?)
Next cntrlItem
Can you or someone fill the “??” blank?
Thank you.
Extract Bookmarks Value From Word.doc (part 2)
Dim w As Word.Document
Dim a As Word.Application
Dim output1 As String
Set a = New Word.Application
Set w = New Word.Document
Set w = a.Documents.Open("c:my document est303.doc")
RobDog888
Ultra-Member
Registered: Apr 01
Location: Los Angeles, CA.
Posts: 2625
visual basic code:--------------------------------------------------------------------------------
msgbox w.Bookmarks("Text1").Range.Text
===========================================================================
Thank you very much, RobDog888.
Part 2:
I have about 42 bookmarks fields in a word doc. -> output1 = w.Bookmarks.Count /** to get the number of bookmarks in the doc.
Now I need to extract EACH of bookmarks value from the doc, and I think “for loop” should do it. However, I failed.
Dim CurrentField as String
Dim result as string
result = “”
For i = 0 to (a.ActiveDocument.Bookmarks.Count) - 1
CurrentField = w.Bookmarks.Item(i) -> Run-time error ‘5941’
-> The requested member of collection does not exit
result = result ^ w.Bookmarks(CurrentField).Range.Text ^ chr(13)
Next i
How to define “collection” for this case?
Your help is greatly appreciated.
Finding The (part Of The) Word User Is Typing
Hey,
In my program I need to know the word that the user is typing.
I know it sounds weird... Ill try to explain:
I'm making some sort of AutoComplete function on a RichTextBox. For this to work I obviously need to know if the (part of the) word the user is typing matches one of the keywords that will be autocompleted.
A "word" is for me defined by a string of characters that begin after a space, tab , newline or "nothing"...
I'm using the following code for now:
(In the rtb_SelChange event)
vb Code:
With rtb
If .SelStart = 0 Then
lSpacePos = 0
Else
'Search start of word position (lSpacePos)
lSpacePos = InStrRev(.Text, vbNewLine, .SelStart)
If InStrRev(.Text, vbTab, .SelStart) > lSpacePos Then
lSpacePos = InStrRev(.Text, vbTab, .SelStart)
End If
If InStrRev(.Text, " ", .SelStart) > lSpacePos Then
lSpacePos = InStrRev(.Text, " ", .SelStart)
End If
End If
'Word:
sWord = Mid$(.Text, lSpacePos + 1, .SelStart - lSpacePos)
End With
As you might be able to see (or not), all it does is check where the word the user is currently typing started.
It finds the first occurence of a space, tab or newline (looking backwards) (this is the InStrRev() part) and constructs the word out of that (by using a Mid$() function starting at the found position of the space tab or newline, with a length of the current selstart - position of space tab or newline).
I've got the feeling nobody will understand this but I hope someone does
Well anyway, it all works out great when...:
- The user starts typing at selstart = 0 (very beginning of rtb)
- The user starts typing after a space
- The user starts typing after a tab
However, it does NOT work when I type a NewLine (enter) and start typing the word then.
The character infront of the word (actually, there is none) is not a Newline for some reason I guess...
Why doesn't this work? I would have thought that when you start a newline, the character infront of that newline is the vbNewLine character?
Finding The (part Of The) Word User Is Typing
Well maybe if I formulate the question differenltly people might understand
----------
In my program I need to know the word that the user is typing.
I know it sounds weird... Ill try to explain:
I'm making some sort of AutoComplete function on a RichTextBox. For this to work I obviously need to know if the (part of the) word the user is typing matches one of the keywords that will be autocompleted.
A "word" is for me defined by a string of characters that begin after a space, tab , newline or "nothing"...
I'm using the following code for now:
(In the rtb_SelChange event)
vb Code:
With rtb If .SelStart = 0 Then lSpacePos = 0 Else 'Search start of word position (lSpacePos) lSpacePos = InStrRev(.Text, vbNewLine, .SelStart) If InStrRev(.Text, vbTab, .SelStart) > lSpacePos Then lSpacePos = InStrRev(.Text, vbTab, .SelStart) End If If InStrRev(.Text, " ", .SelStart) > lSpacePos Then lSpacePos = InStrRev(.Text, " ", .SelStart) End If End If 'Word: sWord = Mid$(.Text, lSpacePos + 1, .SelStart - lSpacePos)End With
As you might be able to see (or not), all it does is check where the word the user is currently typing started.
It finds the first occurence of a space, tab or newline (looking backwards) (this is the InStrRev() part) and constructs the word out of that (by using a Mid$() function starting at the found position of the space tab or newline, with a length of the current selstart - position of space tab or newline).
I've got the feeling nobody will understand this but I hope someone does
Well anyway, it all works out great when...:
- The user starts typing at selstart = 0 (very beginning of rtb)
- The user starts typing after a space
- The user starts typing after a tab
However, it does NOT work when I type a NewLine (enter) and start typing the word then.
The character infront of the word (actually, there is none) is not a Newline for some reason I guess...
Why doesn't this work? I would have thought that when you start a newline, the character infront of that newline is the vbNewLine character?
Selecting A Bookmark In WORD From VB6
I've been working on a VB app on a certain machine for a while, and got it to work.
Now I'm working on a different machine trying to get the same app to work, and I'm having problems. I got through a couple of DLL issues.
The app reads from a MSDE database and generates a WORD document, plugging in data from the database into the appropriate bookmarks on the document.
I have a ton of lines of code like this one, and now it's failing:
WordDoc.Bookmarks("bookmark_name").Select
I'm getting this error:
Object variable or With block variable not set
I made sure the word document I'm working on is where it should be. The code is finding the document. I checked a bookmark and verified that it's still in the document.
Does anyone have an idea as to why the same line of code works on one machine and not another? Could it be a another DLL issue? I'm completely baffled on this one.
Thanks...
Laz
VBA Selecting A Picture In MS Word
Hi,
I would like to know the syntax to select a picture (and more than 1 picture) and format the picture like bring to front and send to back.
Thanks.
Selecting Certain Range In Word Using VB6.0
Hi,
Can anyone please help me?
I am trying to build program that automatically copies certain information in a Word Document and copy it to a specific cell of an Excel Document. I have a questions regarding Selecting certain range within a Word document. However, I am not sure if this can be done...
--> How do you write a code that will search a word document and look for "Sort Total" in that word document (Assuming there is only one "Sort Total".), and then selecting characters# 20 to 22 exactly 5 sentence below the "Sort Total"?
The reason I need to do this is because I am given multiple word documents in similar formats, with a specific table under the title "Sort Total", but the location of that table is different from file to file, so I cannot simply set up a range code to extract the information for every word document.
PS: OR if anyone could tell me how to convert Word Tables into Excel Tables? The problem is that the file is in .sum extension (openable by word), but it reads as pure text and the table is actually word columns/rows aligned, but not in actual table within the document.
---------
The following link is the most related information I've found on the net...
http://msdn.microsoft.com/library/d.../WordObject.asp
This Information is for .NET, but I need VB6.0.
Selecting A Whole Page Of A Word Doc.
I only want to select the whole text of a concret page that is in a word document.
I dont know how to start the selection at start of page, and end the selection at end of page.
Thanks!
sercrusa
Selecting Text In Word
How can I set a cursor in a spesific place in a Word document with a macro? I would need a code, that selects the path from hyperlink code just like user would have drag over it with mouse. Finding a link code is not the problem but dealing with select/cursor.
|