Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2012, 02:21 PM
gurp99 gurp99 is offline Text Spacing in document Windows Vista Text Spacing in document Office 2007
Novice
Text Spacing in document
 
Join Date: Apr 2010
Posts: 18
gurp99 is on a distinguished road
Default Text Spacing in document

hello,



I am trying have text that comes from a macro field automatically aligned in the document.
After the text is added to the document, the second line of the text starts on a new line, I need the second line indented like the first line.

How can I do this?

See attachment.
thanks
Attached Images
File Type: jpg sd.jpg (39.1 KB, 13 views)
Reply With Quote
  #2  
Old 03-13-2012, 03:37 PM
macropod's Avatar
macropod macropod is offline Text Spacing in document Windows 7 64bit Text Spacing in document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,379
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your code that inserts the content of the 'enclosures' box needs to use something like:
.Text = Replace(Enclosures.Text, vbcr, ", ")
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-13-2012, 03:44 PM
gurp99 gurp99 is offline Text Spacing in document Windows Vista Text Spacing in document Office 2007
Novice
Text Spacing in document
 
Join Date: Apr 2010
Posts: 18
gurp99 is on a distinguished road
Default

Does this look coorect?

Code:
Private Sub txtEnclosureAttached_Change()
Dim Rng As Range
Set Rng = ActiveDocument.Bookmarks(""bmkEnclosureAttached"").Range
With Rng
  .Text = Replace(Enclosures.Text, vbcr, ", ")
  Application.ScreenRefresh
End With 
ActiveDocument.Bookmarks.Add ""bmkEnclosureAttached"", Rng 
End Sub

Last edited by macropod; 03-13-2012 at 04:57 PM. Reason: Added code tags
Reply With Quote
  #4  
Old 03-13-2012, 03:57 PM
macropod's Avatar
macropod macropod is offline Text Spacing in document Windows 7 64bit Text Spacing in document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,379
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

No. Instead of (""bmkEnclosureAttached"") you should have (bmkEnclosureAttached). I'd also question why you're using a Change event instead of the Update event. The change event is really only useful if you want edits on the userform to be reflected in the document as they're being typed, rather than once the typing's been completed and you exit the textbox.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-13-2012, 04:03 PM
gurp99 gurp99 is offline Text Spacing in document Windows Vista Text Spacing in document Office 2007
Novice
Text Spacing in document
 
Join Date: Apr 2010
Posts: 18
gurp99 is on a distinguished road
Default

I am still learning the VB language. I am more of a designer than programmer... How does this look:

Code:
Private Sub txtEnclosureAttached_Update()
Dim Rng As Range
Set Rng = ActiveDocument.Bookmarks(bmkEnclosureAttached).Range
With Rng
  .Text = Replace(Enclosures.Text, vbCr, ", ")
  Application.ScreenRefresh
End With 
ActiveDocument.Bookmarks.Add bmkEnclosureAttached, Rng 
End Sub

Last edited by macropod; 03-13-2012 at 04:58 PM. Reason: Added code tags
Reply With Quote
  #6  
Old 03-13-2012, 05:00 PM
macropod's Avatar
macropod macropod is offline Text Spacing in document Windows 7 64bit Text Spacing in document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,379
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Yes, that looks OK, though you don't need the With .. End With structure given you're only doing one thing with the range:
Code:
Private Sub txtEnclosureAttached_Update()
Dim Rng As Range
Set Rng = ActiveDocument.Bookmarks(bmkEnclosureAttached).Range
Rng.Text = Replace(Enclosures.Text, vbCr, ", ")
Application.ScreenRefresh
ActiveDocument.Bookmarks.Add bmkEnclosureAttached, Rng 
End Sub
You also don't need the 'Application.ScreenRefresh' unless it's important to be able to see the document update.

PS: Please use code tags when posting code - you can find them on the Advanced tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 03-13-2012, 05:21 PM
gurp99 gurp99 is offline Text Spacing in document Windows Vista Text Spacing in document Office 2007
Novice
Text Spacing in document
 
Join Date: Apr 2010
Posts: 18
gurp99 is on a distinguished road
Default

Everytime I try to edit the EnclosureAttached field, it comes up blank.. what am I doing wrong here:

see attached
Attached Images
File Type: jpg asd.jpg (35.0 KB, 13 views)
Reply With Quote
  #8  
Old 03-13-2012, 05:25 PM
macropod's Avatar
macropod macropod is offline Text Spacing in document Windows 7 64bit Text Spacing in document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,379
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Sorry, you need to use:
Rng.Text = Replace(txtEnclosureAttached.Text, vbCr, ", ")
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 03-14-2012, 09:12 AM
gurp99 gurp99 is offline Text Spacing in document Windows Vista Text Spacing in document Office 2007
Novice
Text Spacing in document
 
Join Date: Apr 2010
Posts: 18
gurp99 is on a distinguished road
Default

This is the code I have. I have a Update and a Change event. Should I remove the change event?
and what does vbCr, ", " mean?


Code:
Private Sub txtEnclosureAttached_Update()
Dim Rng As Range
Set Rng = ActiveDocument.Bookmarks(bmkEnclosureAttached).Range
    Rng.Text = Replace(txtEnclosureAttached.Text, vbCr, ", ")

Application.ScreenRefresh
ActiveDocument.Bookmarks.Add "bmkEnclosureAttached", Rng
End Sub



Private Sub txtEnclosureAttached_Change()
Dim Rng As Range
Set Rng = ActiveDocument.Bookmarks("bmkEnclosureAttached").Range
    Rng.Text = Replace(txtEnclosureAttached.Text, vbCr, ", ")

Application.ScreenRefresh
ActiveDocument.Bookmarks.Add "bmkEnclosureAttached", Rng
End Sub
Reply With Quote
  #10  
Old 03-14-2012, 02:35 PM
macropod's Avatar
macropod macropod is offline Text Spacing in document Windows 7 64bit Text Spacing in document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,379
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by gurp99 View Post
This is the code I have. I have a Update and a Change event. Should I remove the change event?
Yes.
Quote:
and what does vbCr, ", " mean?
As you can see from the code, it's part of a Replace expression:
Replace(txtEnclosureAttached.Text, vbCr, ", ")
which basically says to replace any carriage returns in the 'txtEnclosureAttached.Text' with a comma followed by a space.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug in PPT 2007 - Font and line spacing in text boxes Amateur PowerPoint 0 09-01-2010 03:34 AM
How do I import text columns with specified spacing between words w/o losing format? Fucius Word 0 08-09-2010 06:23 PM
Text Spacing in document Import Text from File - Line Spacing marshalx Word 2 10-28-2009 02:37 AM
Print spacing in Word document veekay99 Word 16 04-21-2009 01:18 AM
How to link text from one document to another nospamforyou Word 0 10-09-2008 09:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:43 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft