MACRO BUTTON-help need

T

Thejan Mendis

Hi all,

I am really enjoy VBA these days and I want to push my limit to the sky.

This is what I need

* How do I put a new paragraphs or new line through the vba command.
* Pls c whether this is possible

1. An opened document I select some text,
2. By pressing a macro button or something, it will create new document
with my selected text

IS IT POSSIBLE


I hope somebody can help me


THEJAN
 
M

Mark Tangard

Hi thejan,

Both very easy:

To insert a new paragraph:

Selection.InsertAfter "text of your paragraph" & vbCr
Selection.Collapse wdCollapseEnd

(But be aware that using VBA just to type text is not really
efficient; if you're inserting the same text often, it's
smarter to make it an AutoText. If you're placing text
into a complex document or in a header, footer, textbox,
etc., it's smarter to use Range objects rather than the
Selection.)

For your second question:

Dim r as range
Dim newdoc as Document
Set r = Selection.Range
Set newdoc = Documents.Add
newdoc.Range.Text = r.Text

or if you wanted to capture the formatting of the text as
well, the last line would be:

newdoc.Range.FormattedText = r.Formatted.Text

Hope this helps.
 
T

Thejan Mendis

Thanks Mark. that was really helpul.

THEJAN



Mark Tangard said:
Hi thejan,

Both very easy:

To insert a new paragraph:

Selection.InsertAfter "text of your paragraph" & vbCr
Selection.Collapse wdCollapseEnd

(But be aware that using VBA just to type text is not really
efficient; if you're inserting the same text often, it's
smarter to make it an AutoText. If you're placing text
into a complex document or in a header, footer, textbox,
etc., it's smarter to use Range objects rather than the
Selection.)

For your second question:

Dim r as range
Dim newdoc as Document
Set r = Selection.Range
Set newdoc = Documents.Add
newdoc.Range.Text = r.Text

or if you wanted to capture the formatting of the text as
well, the last line would be:

newdoc.Range.FormattedText = r.Formatted.Text

Hope this helps.

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters
 
T

Thejan Mendis

Hi Mark,

May be I want to put you on a treble. This is what I want to do.

I have a document with lot of text. but I want only little. I need those
text to be format as follows,


-DATE- 20030601
-PAGE- 18
-HEAD- In a Manner of Speaking


-TEXT-

THE BEST PRESENTATION I've recently seen lacked humor, grace, and
PowerPoint.

The speaker was cranky, opinionated, and perfectly willing to ****

-END-

by using your macro I tried to create a macro with 4 button
(-DATE-/ -PAGE-/ -HEAD-/ -TEXT-). What I do I select some text and press the
relevant button and It will automatically go to new document with text and
field Name (DATE, HEAD). (as above)

Now I have these problem

1. Every time I press the button it will create new document with my
selected text. But what I need all the text to go the a one document in
order to my button selection. and it has to maintain the blank paragraphs
and filed names (-DATE-/ -PAGE-/ -HEAD).

2. but when I inserting second paragraphs or second headline it should not
print filed name.

-HEAD- In a Manner of Speaking
-HEAD- Speaking Of Macro

it should be...
-HEAD- In a Manner of Speaking
Speaking Of Macro


I hope you can help me to find a solution.



THEJAN
 
T

Thejan Mendis

Hi Great Mark,


Yes It does, But The Problem is, since I have three text box do I have to
repeat the cord for three uppercase button or is there any way I can use one
button to change text into upper case for all text book immmmmmmmm maybe
something like this like this.. (Iam sure its Wrong)

Private Sub CommandButton5_Click()

IF TextBox1.SelText
TextBox1.SelText = UCase(TextBox1.SelText)
Elese
IF TextBox2.SelText
TextBox2.SelText = UCase(TextBox2.SelText)
Else
TextBox3.SelText = UCase(TextBox3.SelText)
End If

End If
End Sub

THEJAN
 
T

Thejan Mendis

Hi Mark,


Sorry to trouble you by sending an email to your privet mail box mistakenly.
Actually I send the mail with out reading you advice Please bear with me for
this time.

And I must really Appreciate the way you have help me so far. It was really
helpful and made me Microsoft lover. Since I am living in Sri Lanka it is
very difficult to find such invaluable advice.

I would like whish you success in your every dreams and works also to the
all the members in MVP and Microsoft who help me to find a way to do things
much easier.


Thanks guys

very best wishes and worm regards


THEJAN
 
M

Mark Tangard

You can do it with one if you cycle through the controls,
but for a beginner that's quite a bit more trouble than
it's probably worth. It also only works if you're doing
it for *all* textboxes, or all textboxes named in a certain
way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top