Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...thank you for the wonderful resource that you have enabled here. It is clear, concise, well maintained and most importantly, helpful..."

Geography

Where in the world do Tek-Tips members come from?
reggie55555 (MIS)
15 Aug 12 17:06
chr(13) (and "^p") in a VBA macro is sometimes skipped when the macro is run. The macro is intended to insert various predefined strings into a word doc.

Example:

CODE

istring(1) = "This is some text"
istring(2) = "This is more text that appears in a new paragraph"

Set objselection = wdAPP.Selection
With objselection
       .EndKey wdStory, wdMove
       .Font.Size = 10
       .TypeText Chr(13) & istring(1) & Chr(13) & Chr(13) & istring(2) & Chr(13)
End With 

Does anyone know why this may be happening?

Here is a sample of the desired result:

CODE

This is some text

This is more text that appears in a new paragraph 

Here is an example of when the chr(13) is skipped:

CODE

This is some textThis is more text that appears in a new paragraph 
macropod (TechnicalUser)
15 Aug 12 18:59
Typing Chr(13) does not insert a paragraph break - only a character that looks like one. To insert a paragraph break you should use vbCr or vbCrLf.

Cheers
Paul Edstein
[MS MVP - Word]

strongm (MIS)
16 Aug 12 3:56
Er ... vbCR is CHR(13)

>Typing Chr(13) does not insert a paragraph break

Does for me. Has done for years.

As does Chr(10). And CHR(13) & CHR(10). (vbLf and vbCrLf)

However, .TypeText seems to do odd things with control characters on rare occassion (I suspect because it is playing around with the keyboard buffer). I prefer to use .TypeParagraph to reliably insert a paragraph break. Or, given that in this case we are collapsing a selction into an insertion point, we could just use .Text, which seems happier with control characters, instead of .TypeText
MakeItSo (Programmer)
16 Aug 12 4:17
How about using

CODE

.TypeParagraph 
to insert a paragraph marker?

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

strongm (MIS)
16 Aug 12 5:12
Too slow winky smile
macropod (TechnicalUser)
16 Aug 12 5:13
Sorry folks, I was thinking more in terms of what happens when one uses when one inserts ^13 Chr(13) as the replacement text via Find/Replace. I saw the OP's reference to ^p and made the wrong association.

Cheers
Paul Edstein
[MS MVP - Word]

MakeItSo (Programmer)
16 Aug 12 5:35
Argh! Should have read your post with more attention. blush
Anyhow, vbNewLine should do the trick too.
There are so many ways to make a cat meow. tongue

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

strongm (MIS)
16 Aug 12 5:41
Indeed

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close