Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counting of characters in order to delete them

Status
Not open for further replies.

Pegasus0990

Technical User
Nov 16, 2006
27
0
0
US
2) if i do "Wordcount" in Microsoft Word it gives me a certain amount of characters that exist in my document. but if i tell my code to delete that many characters as in
Selection.Delete Unit:=wdCharacter, Count:=1996
even if my document says that there are 1996 characters, it acutally always fall short. why? does anybody know a better way to delete this code? Note, I am using multiple bookmarks and i cannot have the code delete too many characters, else it will delete my bookmarks

[VBCODE]
Public Sub CommandButton1_Click()
HideListBoxes

Dim oDoc As Word.Document

Set oDoc = Application.Documents("C:\Documents and Settings\word.doc")
Dim oExcel As Excel.Application, myWB As Excel.Workbook

Set oExcel = New Excel.Application
Set myWB = oExcel.Workbooks.Open("C:\Documents and Settings\excel.xls")

h = 2
i = 4
j = 6
l = 7

If Worksheets("Calculations").Cells(1, 1) = "0" Then
Selection.GoTo What:=wdGoToBookmark, Name:="part1"

Selection.Delete Unit:=wdCharacter, Count:=1996
Else
If Worksheets("Calculations").Cells(2, 1) = "0" Then
Selection.GoTo What:=wdGoToBookmark, Name:="one"
With Selection
.EndOf Unit:=wdParagraph, Extend:=wdExtend
.TypeBackspace
End With
Selection.Delete Unit:=wdCharacter, Count:=985
End if
End Sub
[/VBCODE]
 
It may not account for white-space(space/tab...) characters in the count, but does in the delete function???
 
when i use the delete function it works, deletes bookmarks, characters, tabs, spaces, etc.

the following works well because it will do everything i desire but for just one line. i am looking for something to delete around six lines at once (and it is not one paragraph).

Selection.Bookmarks("\Line").Range.Delete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top