Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Helmut or Jezebel re Bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
singeredel - 28 Feb 2005 15:41 GMT
Please see my last post under "Inserting variables in multiple bookmarks". I
have set the range and selected the range, but I still cannot get the text to
be formatted as indicated. I am trying to go to a specific bookmark and
insert and format the text. The last If..End If statement is to delete the
line in the document if there is no text for that line.

Any help would be appreciated.  Thank you!
Signature

singeredel

Greg - 28 Feb 2005 16:32 GMT
Am an neither Jezebel or Helmut so it that matters then disregard.

Sub Test()
Dim bBkm As String
Dim bText As String
Dim bIndex As Long
For bIndex = 1 To 5
Dim oRng As Range

bBkm = Choose(bIndex, "ReportAddress1", "ReportAddress2",
"ReportAddress3", "ReportAddress4", "ReportAddress5")
bText = Choose(bIndex, ReportAddress1$, ReportAddress2$,
ReportAddress3$, ReportAddress4$, ReportAddress5$)
Set oRng = ActiveDocument.Bookmarks(bBkm).Range
oRng.Text = bText
If bIndex = 4 Or bIndex = 5 Then
 oRng.Paragraphs.Style = "Body Text"
End If
If bIndex = 1 Then
 oRng.Font.AllCaps = True
End If
If bIndex = (4 Or bIndex = 5) And Len(bText) = 0 Then
 oRng.Delete Count:=1
End If
Next
End Sub
singeredel - 28 Feb 2005 17:15 GMT
Greg -- Thank you! I was more than happy to get your response. Everything
that you had worked with one exception, the last set of instructions
regarding deleting the line: Although when stepping through the code, it
showed that bIndex was = 5 and Len(bText) was =0, it skipped over the
oRng.Delete to the End If, so the line was not deleted. I don't understand
why the next step was skipped when all the criteria were met.

> Am an neither Jezebel or Helmut so it that matters then disregard.
>
[quoted text clipped - 22 lines]
> Next
> End Sub
Helmut Weber - 28 Feb 2005 16:39 GMT
Hi (firstname?),

there are two kinds of bookmarks,
short ones similar to ][, and long ones [Bookmark Text],
which behave very differently.
Short Bookmarks
  cannot be deleted by typing backspace
  don't have a range.text, in a way
  ActiveDocument.Bookmarks("Short").Range.Text = "xxx"
  MsgBox ActiveDocument.Bookmarks("Short").Range.Text ' ""
  MsgBox Len(ActiveDocument.Bookmarks("Short").Range.Text) ' 0
  are still there after assigning text to their range
  ActiveDocument.Bookmarks("Short").Range.Text = "xxx"
  MsgBox ActiveDocument.Bookmarks.Exists("Short")
Long Bookmarks
  can be deleted by typing backspace
  have a range text
  vanish after assigning text to their range !!!
  MsgBox ActiveDocument.Bookmarks("Long").Range.Text
  MsgBox Len(ActiveDocument.Bookmarks("Long").Range.Text)
  ActiveDocument.Bookmarks("Long").Range.Text = "longlong"
  MsgBox ActiveDocument.Bookmarks.Exists("Long") ' false !!!

Don't give up, ca all be handled!

What kind of bookmarks do you use?
I don't hope both kinds.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
singeredel - 28 Feb 2005 16:53 GMT
I didn't know there was more than one kind of bookmark, but they do go away
when I backspace, but they do not disappear when I place text there, as I can
still see the bookmark indicator in the document.

> Hi (firstname?),
>
[quoted text clipped - 30 lines]
> Word XP, Win 98
> http://word.mvps.org/
Helmut Weber - 28 Feb 2005 17:25 GMT
Hi (firstname?),
(would really be nice to be on confident terms,
no MVP here hides his name,)

Sub test9999()
Dim s As String ' text to be inserted
Dim l As Long   ' lenght of that text
Dim r As Range  ' the range which that text occupies
Set r = Selection.Range ' initializing the range
' other methods of coding possible
s = "Text In Capitals"
l = Len(s)
' add text from the bookmark on
ActiveDocument.Bookmarks("Short2").Range.Text = s
' get the range of the inserted text
r.Start = ActiveDocument.Bookmarks("Short2").Range.Start
' extend the range according to the lenght
' of the inserted text
r.End = r.Start + l
r.Font.AllCaps = True
End Sub

HTH

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
singeredel - 28 Feb 2005 18:09 GMT
Hi Helmut. My name is Julie. Please excuse my etiquette. I am new to these
forums and am not aware of all the formalities. Thank you so much for your
help!

> Hi (firstname?),
> (would really be nice to be on confident terms,
[quoted text clipped - 26 lines]
> Word XP, Win 98
> http://word.mvps.org/

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.