peaceowner |
|
1 |
|
16.12.2010, 19:34. Показов 24955. Ответов 9
Ребята хелп ми, уже из сил выбился. Как выделить отдельную строку в ячейке таблицы Word? Ставлю курсор в начало строки и пробую различные методы типа MoveEnd(), EndOf(), MoveEndUntil() и другие. Все эти методы выделяют ВСЕ строки ячейки. Я даже в ворде проверил, поставил курсор на начало 2ой(из 4ех) строки ячейки и нажал клавишу End с зажатым Шифтом. В итоге выделились ВСЕ строки ячейки включая первую. Опытным путем установил, что двигаться нужно посимвольно, тогда строка выделяется как надо. Вопрос, как мне переместить выделение до последнего символа последней строки ячейки? Вообще пишу на Делфи, но все методы из ВБА. Помогите плиз. З.Ы. Забыл сказать, что строки ничем не разделены. Знаков переноса каретки нет, т.е. клавиша «интер» не нажималась, а просто сплошняком заполнялся текст в ячейку. |
1508 / 478 / 56 Регистрация: 10.04.2009 Сообщений: 8,008 |
|
16.12.2010, 20:29 |
2 |
АктивеДокумент.Таблес(1).Ровс(1).Селект
1 |
306 / 187 / 26 Регистрация: 14.02.2010 Сообщений: 540 |
|
16.12.2010, 20:30 |
3 |
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
1 |
peaceowner |
|
16.12.2010, 20:48 |
4 |
Всем спасибо, разобрался наконец) Узнал позиции первого и последнего символов желаемого выделения. А дальше при помощи SetRange установил нужное мне выделение. kukuruku310 |
Ципихович Эндрю 1508 / 478 / 56 Регистрация: 10.04.2009 Сообщений: 8,008 |
||||||||
17.12.2010, 03:30 |
5 |
|||||||
Что Вам здесь
и здесь
не понравилось
0 |
306 / 187 / 26 Регистрация: 14.02.2010 Сообщений: 540 |
|
17.12.2010, 12:32 |
6 |
да хоть в таблице, хоть в тексте, Shift+End работает одинаково, проверьте настройки Word. Я сам не пользуюсь ничем, кроме 97, поэтому конкретнее сказать не могу. Миниатюры
0 |
306 / 187 / 26 Регистрация: 14.02.2010 Сообщений: 540 |
|
17.12.2010, 14:46 |
7 |
Щательнее подумавши еще добавлю: в последней строке ячейки действительно будет выделять весь текст целиком. Во избежание, наиболее просто, моно сделать финт ушами: запомнить текущую позицию Range — это будет начало диапазона, а для определения его конца перейти в конец строки без выделения. Как второй вариант, использовать переход в начало (Shift+Home), который, в отличие от Shift+End, всегда срабатывает одинаково, но это более заморочно, если выделять не от начала строки.
0 |
Ksenya100 72 / 64 / 3 Регистрация: 13.05.2010 Сообщений: 349 |
||||
27.02.2012, 18:11 |
8 |
|||
в эту же тему
но так, естественно не работает. я так поняла peaceowner, разобрался…?
0 |
Ципихович Эндрю 1508 / 478 / 56 Регистрация: 10.04.2009 Сообщений: 8,008 |
||||
27.02.2012, 18:30 |
9 |
|||
2 |
72 / 64 / 3 Регистрация: 13.05.2010 Сообщений: 349 |
|
27.02.2012, 18:50 |
10 |
Ципихович Эндрю, Спасибо!!
0 |
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Contact US
Thanks. We have received your request and will respond promptly.
Log In
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips Forums!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts - Keyword Search
- One-Click Access To Your
Favorite Forums - Automated Signatures
On Your Posts - Best Of All, It’s Free!
*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Students Click Here
How do I select the first 2 rows of a table in wordHow do I select the first 2 rows of a table in word(OP) 25 Jun 09 04:13 Hey there, this is a pretty simple question — I just need help because when I run the macro recorder I can’t select stuff with the mouse, I need to select the first 2 rows in a table in Word so I can set them as header rows: eg. ‘Set the first two rows as repeatable heading rows I just need to know how to do selections or define ranges in word VBA and I just can’t get it right at the moment Thanks, Red Flag SubmittedThank you for helping keep Tek-Tips Forums free from inappropriate posts. |
Join Tek-Tips® Today!
Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.
Here’s Why Members Love Tek-Tips Forums:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More…
Register now while it’s still free!
Already a member? Close this window and log in.
Join Us Close
VBA Select
It is very common to find the .Select methods in saved macro recorder code, next to a Range object.
.Select is used to select one or more elements of Excel (as can be done by using the mouse) allowing further manipulation of them.
Selecting cells with the mouse:
Selecting cells with VBA:
'Range([cell1],[cell2])
Range(Cells(1, 1), Cells(9, 5)).Select
Range("A1", "E9").Select
Range("A1:E9").Select
Each of the above lines select the range from «A1» to «E9».
VBA Select CurrentRegion
If a region is populated by data with no empty cells, an option for an automatic selection is the CurrentRegion property alongside the .Select method.
CurrentRegion.Select will select, starting from a Range, all the area populated with data.
Range("A1").CurrentRegion.Select
Make sure there are no gaps between values, as CurrentRegion will map the region through adjoining cells (horizontal, vertical and diagonal).
Range("A1").CurrentRegion.Select
With all the adjacent data
Not all adjacent data
«C4» is not selected because it is not immediately adjacent to any filled cells.
VBA ActiveCell
The ActiveCell property brings up the active cell of the worksheet.
In the case of a selection, it is the only cell that stays white.
A worksheet has only one active cell.
Range("B2:C4").Select
ActiveCell.Value = "Active"
Usually the ActiveCell property is assigned to the first cell (top left) of a Range, although it can be different when the selection is made manually by the user (without macros).
The AtiveCell property can be used with other commands, such as Resize.
VBA Selection
After selecting the desired cells, we can use Selection to refer to it and thus make changes:
Range("A1:D7").Select
Selection = 7
Selection also accepts methods and properties (which vary according to what was selected).
Selection.ClearContents 'Deletes only the contents of the selection
Selection.Interior.Color = RGB(255, 255, 0) 'Adds background color to the selection
As in this case a cell range has been selected, the Selection will behave similarly to a Range. Therefore, Selection should also accept the .Interior.Color property.
RGB (Red Green Blue) is a color system used in a number of applications and languages. The input values for each color, in the example case, ranges from 0 to 255.
Selection FillDown
If there is a need to replicate a formula to an entire selection, you can use the .FillDown method
Selection.FillDown
Before the FillDown
After the FillDown
.FillDown is a method applicable to Range. Since the Selection was done in a range of cells (equivalent to a Range), the method will be accepted.
.FillDown replicates the Range/Selection formula of the first line, regardless of which ActiveCell is selected.
.FillDown can be used at intervals greater than one column (E.g. Range(«B1:C2»).FillDown will replicate the formulas of B1 and C1 to B2 and C2 respectively).
VBA EntireRow and EntireColumn
You can select one or multiple rows or columns with VBA.
Range("B2").EntireRow.Select
Range("C3:D3").EntireColumn.Select
The selection will always refer to the last command executed with Select.
To insert a row use the Insert method.
Range("A7").EntireRow.Insert
'In this case, the content of the seventh row will be shifted downward
To delete a row use the Delete method.
Range("A7").EntireRow.Delete
'In this case, the content of the eighth row will be moved to the seventh
VBA Rows and Columns
Just like with the EntireRow and EntireColumn property, you can use Rows and Columns to select a row or column.
Columns(5).Select
Rows(3).Select
To hide rows:
Range("A1:C3").Rows.Hidden = True
In the above example, rows 1 to 3 of the worksheet were hidden.
VBA Row and Column
Row and Column are properties that are often used to obtain the numerical address of the first row or first column of a selection or a specific cell.
Range("A3:H30").Row 'Referring to the row; returns 3
Range("B3").Column 'Referring to the column; returns 2
The results of Row and Column are often used in loops or resizing.
Consolidating Your Learning
Suggested Exercise
SuperExcelVBA.com is learning website. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. All Rights Reserved.
Excel ® is a registered trademark of the Microsoft Corporation.
© 2023 SuperExcelVBA | ABOUT