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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to insert a symbol 2

Status
Not open for further replies.

pmcdaniel

Programmer
Feb 9, 2007
127
US
I'm trying to insert the Registrations symbol into a Word doc through VB.

Everything works except the symbol does not get inserted. Here's the code:

AppWd.ActiveDocument.Variables.Item("varname").Value = "text before symbol"


' AppWd.Selection.Font.Superscript = True
' AppWd.Selection.InsertSymbol Font:="Symbol", CharacterNumber:=-3870, Unicode:=True
' AppWd.Selection.Font.Superscript = False


AppWd.ActiveDocument.Application.Selection.Font.Superscript = True
AppWd.ActiveDocument.Application.Selection.InsertSymbol Font:="Symbol", CharacterNumber:=-3870, Unicode:=True
AppWd.ActiveDocument.Application.Selection.Font.Superscript = False

AppWd.ActiveDocument.Variables.Item("varname").Value = AppWd.ActiveDocument.Variables.Item("varname").Value & ", the rest of my text"


The code in green is commented out to show that I had tried another way.

As you can see after my attempt to insert the symbol I am concatenating the original text with the rest of it's value.

Everything shows correctly EXCEPT the inserted symbol. Please help

thanks
 
It works for me. I am a bit confused about what you are doing though - where are you expecting the (R) to go and where are you expecting the rest of the text to go?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
I'm expecting something like text before symbol(R), the rest of my text. The (R) being the inserted symbol(or the Registered symbol). Here is what shows:
text before symbol, the rest of my text

I am using document variables because the text I'm trying to insert is inside a vb Select statement....it can be any of several company names with additional information depending on certain criteria and some use that symbol. I DO NOT want to put several If statements in the document to do this.

I appreciate your help
 
I'm still confused. You put "text before symbol, the rest of my text" in the document variable, and you put (R) separately in the document. Are you perhaps adding the variable to the document later and overwriting the (R)? It's difficult to tell when we clearly only have part of your code.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
I put text before symbol then I attempt to insert the symbol, then I attempt to put in , the rest of my text Is there a way to put in the symbol directly in the value of my docvariable?

I also tried to just put in text before symbol and then the symbol without the second part of the variable and it still does not show.

AppWd.ActiveDocument.Variables.Item("mncert_ClaimsProvisionsCompany").Value = "text before symbol"
AppWd.ActiveDocument.Application.Selection.Font.Superscript = True
AppWd.ActiveDocument.Application.Selection.InsertSymbol Font:="Symbol", CharacterNumber:=-3870, Unicode:=True
AppWd.ActiveDocument.Application.Selection.Font.Superscript = False


BTW, this is through a Visual Basic 6 application NOT VB in Word.

Everything with AppWd.ActiveDocument.Application.Selection in front of it does not show in the Word doc. Im new at this and am editing an existing app. so the AppWd.ActiveDocument.Application.Selection could be all wrong.
 
I have discovered that it is being inserted at the very beginning of the document(top left corner of the first page)! Now, how do I specify the exact spot to insert the symbol?
 
You should be able to put the symbol, but not the formatting, in the variable if it helps, but I still don't know what you are doing with the doc variables - and this matters because you can certainly specify where in a document to put something (although you will need to have a means of identifying the place) but it won't help if the place you want to put it (and the surrounding context) is not actually in the document at the time.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Okay, I'll try to be more specific and hopefully I can explain it more precise. We have a document with docvariables and bookmarks inside it through-out the text. We run the VB 6 app which opens this document and inserts values into the docvariables and deletes bookmarks when and where pertinent.

One of these docvariables must somehow have the symbol in it(the Registered symbol). This symbol must be inserted as a superscript.
Here is an example of the TM supersript ....trademark symbols ™, and this is similar to what I want to insert.

Thanks for your patience & your help
 
Quickly because I'm on my way out the door but if you have bookmarks for where you want to put text then build it up directly at the bookmark location (look at ActiveDocument.Bookmarks("BookmarkName").Range to find out where they are if you need to). I'm afraid I just don't understand what you're doing with the doc variables at all - in what way are they helping your process?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Maybe I don't need the docvariable to insert the symbol? Not sure what you're talking about with (look at ActiveDocument.Bookmarks("BookmarkName").Range to find out where they are if you need to.

Anyway, right now I'm trying a Find/replace deal....don't know if that will work.
 
I use the doc variables to insert a value in a sentence say:
You have {docvariable varAmountOfTime} to make your claim.

And any one of the following values will be put into varAmountOfTime from the VB 6 code:
1 day
1 week
1 month
1 year

Hope that helps
 
This is confusing, and seems more complex than need be.

If you just want to put text into a specified location, use a bookmark. You can do this by just using the range.

Using a changing font makes it a little harder to just use a range.

Here is an example.

"This is a bunch of words."

Now suppose you want it to look like:

"This is a bunch BlahBlah (R) of words." that is, you want to insert "BlahBlah " and the symbol.

Put a bookmark - I am using "test" - in the space between "bunch" and "of", that is...where you want it.
Code:
Sub FillBookmarkFontChanges(strIn As String)

With Selection
    .GoTo what:=wdGoToBookmark, Name:="test"
    .TypeText Text:=strIn
    .Collapse Direction:=wdCollapseEnd
    .Font.Superscript = True
    .InsertSymbol Font:="Symbol", CharacterNumber:=-3870, _
        Unicode:=True
    .Collapse Direction:=wdCollapseEnd
    .Font.Superscript = False
    .MoveStart Unit:=wdCharacter, Count:=-(Len(strIn) + 1)
End With
ActiveDocument.Bookmarks.Add _
    Name:="test", Range:=Selection.Range

End Sub

Sub InsertSymbol()
  Call FillBookmarkFontChanges ("Blah blah ")
End Sub

Now if you just want to insert text at a bookmark location, with no font changes, it is much easier.
Code:
Sub FillABookmark(strBM_Name As String, strBM_Text As String)
 With Selection
  .GoTo what:=wdGoToBookmark, Name:=strBM_Name
  .Collapse Direction:=wdCollapseEnd
  ActiveDocument.Bookmarks(strBM_Name).Range.Text = _
     strBM_Text
  .MoveEnd unit:=wdCharacter, Count:=Len(strBM_Text)
  ActiveDocument.Bookmarks.Add _
     Name:=strBM_Name, Range:=Selection.Range
  .Collapse Direction:=wdCollapseEnd
 End With
End Sub

Sub InsertText()
  Call FillABookmark("here", "some text")
End Sub

"This is ."

If the bookmark "here" is set at the location just before the period, then running InsertText will make it:

"This is some text."

The handy thing is, by making sure the text is actually IN the bookmark, you can change it to whatever you want.

Running InsertText, but as:
Code:
Call FillABookmark ("here", "a whole big whack of text")

will make it:

"This is a whole big whack of text."

The blank bookmark was replaced with "some text", and then "some text" was replaced with "a whole big whack of text". The text is IN the bookmark.

You can replace the bookmark contents with any string.
Code:
Call FillABookmark ("here", ActiveDocument.Paragraphs(3).Range.Text)
would insert the third paragraph of the document into the bookmark.

I am really not sure what you are doing with the docvariables. For what I can gather about what you are trying to do, they do not seem needed at all.

Gerry
My paintings and sculpture
 
I see Gerry has answered fairly fully but I'll add my bit anyway.

You are complicating things with the doc variables. Put bookmarks where you want to add your text and add it right there. Here is some sample code using Ranges rather than the Selection ...

Code:
[blue]Dim InsertionRange As Range, TempRange As Range
Dim BookmarkStart As Long

Set InsertionRange = ActiveDocument.Bookmarks("Bookmark1").Range

With InsertionRange

    BookmarkStart = .Start [green]' Remember the beginning[/green]

    .Delete
    .InsertAfter ("Text before symbol")
    
    .Collapse wdCollapseEnd
    .InsertSymbol Font:="Symbol", CharacterNumber:=-3870, Unicode:=True
    .End = .End + 1 [green]' InsertSymbol does not redefine the Range
    ' Applying formatting now will affect later inserts
    ' ... so save the range and do it later[/green]
    Set TempRange = .Duplicate
    
    .Collapse wdCollapseEnd
    .InsertAfter (", the rest of my text")

    [green]' Re-insert the Bookmark if you want[/green]
    .Start = BookmarkStart
    ActiveDocument.Bookmarks.Add Name:="Bookmark1", Range:=InsertionRange

    [green]' Now safe to apply superscript to (R) symbol[/green]
    TempRange.Font.Superscript = True
    
End With[/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Thank you both! I've researched my dilemma and found the use of Range which I was not familiar with and didn't have a lot of time to try to learn it so your help here is even more appreciated.

Due to time constraints I did a work around....for now but in the next day or so I'll come back to this and try it all. Don't like to do work arounds so I WILL be back.

Thanks again.

 
Okay, I had time this morning to tackle this thing again and it worked with some small issues(I think) but I'll figure those out.

I really appreciate the help!!!

If you have time can you explain why I/we wouldn't want to use docvariables because they're all over the place in our documents.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top