PDA

View Full Version : square box with question mark symbol



jspattavina
06-09-2010, 12:22 PM
I am using Word VBA to create a word template.

I have a multi-line text box. When I save the contents of the textbox to a document variable and insert the document variable into the word document I get a funny symbol "square box with a question mark inside". I cannot use words find and replace feature to get rid of the symbol. I tryied to paste the symbol into the words replace box but that did not work, since the symbol appears to be unkown to word. If I paste the contents of the text box directly into the document (not using a document variable) then I do not get the symbol. However, I need to insert the text using document variables.

Please help.

fumei
06-09-2010, 12:56 PM
"However, I need to insert the text using document variables. "

Why?

jspattavina
06-09-2010, 01:23 PM
I need to use document variables, since these are inserted in many places in the document (boiler plate type). I need the user to be able to enter text in a text box and update the document variables everywhere in the entire document. I cannot copy/paste since that would require i find each occurance of the particilar text. For example, I have a document variable for client name, cost, introduction, report methodology etc.. So when they click on the update button, all the document info is updated.

I discovered that the square box is Char(13) or Char(10). Therefore I need a way to search the entire document and replace the Char(10) and Char(13) with " ".

Any thoughts?

Tinbendr
06-09-2010, 01:41 PM
Your template is corrupt.

The only way I've been able to make the boxes go away is to export all the modules/userforms and start over with a fresh template, then import.

Good luck.

---------
Disregard, I'm thinking about formfields.

jspattavina
06-09-2010, 02:31 PM
I discovered a way to search for the Char(10) symbol and replace it with " ".
-------------------------------------
Public Sub ReplaceChar10()
' When you write a multi-line textbox to a document variable new lines are
' preceeded by Char(10). In Times, or Arial this shows up as a small square.
' In Calibri it shows up as a square box with a question mark inside.
' The following function searches the entire document for Char(10) and replaces it with ""
Selection.find.ClearFormatting
Selection.find.Replacement.ClearFormatting
With Selection.find
.text = "^010"
.Replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.find.Execute Replace:=wdReplaceAll
End Sub

TonyJollans
06-10-2010, 01:23 AM
If you replace Line Feed characters with nothing ("") you are removing them from the input? Is this what the user wants - all the lines of input run together?

jspattavina
06-10-2010, 07:45 AM
From Tony: If you replace Line Feed characters with nothing ("") you are removing them from the input? Is this what the user wants - all the lines of input run together?

In fact, the Char(10) that I am replacing appears at the beginning of a new line at the end of a paragraph containing the document variable text. So replacing with (" ") gets rid of Char(10) but does not cause the the lines of paragraphs run together.

However, there appears to be two spaces between paragraphs since the Char(10) is replaced with a (" ") and appears on the last line. Then it is followed by the normal paragraph break (^p).

I would prefer to delete the line that Char(10) appears on all together instead of replacing it with (" ")

Any thoughts?

TonyJollans
06-10-2010, 08:38 AM
Why not clear it out before it ever gets to Word?

If you are putting the text in a doucmnet variable, do it this way ..

ActiveDocument.Variables("VarName") = Replace(TextboxName.Text, vbCrlf, vbCr)

fumei
06-10-2010, 09:27 AM
I need the user to be able to enter text in a text box and update the document variables everywhere in the entire document. I cannot copy/paste since that would require i find each occurance of the particilar text. For example, I have a document variable for client name, cost, introduction, report methodology etc.. So when they click on the update button, all the document info is updated.You do NOT need to use DOCVARIABLES to do this. You do NOT need to do a copy/paste either.

Demo attached. The userform is displayed on document open. Put text into the textbox, using Shift-Enter to put multiple lines. Click the commandbutton.

1. the text from the textbox goes to its indicated location.
2. there is no square box
3. the text is duplicated in multiple locations

No document variables used.

I am not saying using doc variables is wrong. I am saying that "I need to use document variables" is an incorrect statement.

You do not need to use document variables.

fumei
06-10-2010, 09:31 AM
Interesting. I just tested my posted file. It does NOT fire Document_Open. Hmmmm.

Reposted. The userform is displayed by clicking "Show My Form" on th etop toolbar.

I hope.

fumei
06-10-2010, 09:32 AM
Good. That works.

Paul_Hossler
06-11-2010, 01:50 PM
Gerry - your doc in #9 does automatically show the Userform on open (in my "2003+4" version of Word

Paul

fumei
06-11-2010, 02:00 PM
Nope. I just tried it again. It does work if I save the file with a TargetAs, and then open it. (Or doing a SaveAs from the attachment.php.)

I was thinking it would fire Open just on clicking it here.

TonyJollans
06-12-2010, 03:22 AM
Paul,

What browser are you using?

Paul_Hossler
06-12-2010, 05:35 AM
Tony

IE8, but I always save files to my Desktop to scan before I open them.

Never occured to me that other people might do it differently, so I never thought to mention that.

Gerry's doc did not fire it's Document_Open if I just tried to open it directly without first saving

Paul

TonyJollans
06-12-2010, 09:20 AM
Thanks, Paul - the 'problem' is something to do with IE security settings, an area I'm really trying to understand. The Open event does fire when opened from Opera and Safari (the two I tried), but not from IE even when vbaexpress is added to Trusted Sites.

fumei
06-14-2010, 09:42 AM
Ditto. It used to fire with IE 6 and IE 7.

jspattavina
08-25-2010, 10:40 AM
thanks