Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

Copy from variant to clipboard

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
keith - 06 Jul 2005 12:20 GMT
Hello

I have some text in a variant variable created with...

Dim MyVariable as variant
MyVariable = "some text"

How do I copy that to the clipboard?

I tried...

selection.copy = MyVariable

but received an error.

any suggestions?

Keith
Jay Freedman - 06 Jul 2005 16:00 GMT
> Hello
>
[quoted text clipped - 14 lines]
>
> Keith

Hi Keith,

You can do either of two things:

(1) Insert the content of the variable into the document and then cut it
from there into the clipboard:

  Dim MyString As Variant
  Dim MyRange As Range
  MyString = "some text"

  ' save the selection
  Set MyRange = Selection.Range

  With Selection
     .Collapse wdCollapseStart
     .Text = MyString
     .Cut
  End With

  ' restore the selection
  MyRange.Select

OR (2) see http://word.mvps.org/FAQs/MacrosVBA/ManipulateClipboard.htm for a
way to place the text directly into the clipboard without messing around in
the document.

One other thing: experience tells me that people often ask about ways to use
the clipboard when they really don't need to use the clipboard at all.
What's the main task you're trying to do?

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

Jean-Guy Marcil - 06 Jul 2005 16:04 GMT
keith was telling us:
keith nous racontait que :

> Hello
>
[quoted text clipped - 8 lines]
>
> selection.copy = MyVariable

This copies the currently selected range in the document, nothing to do with
variables.

> but received an error.
>
> any suggestions?

See
http://word.mvps.org/FAQs/MacrosVBA/ManipulateClipboard.htm

What are you trying to do?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

keith - 06 Jul 2005 17:57 GMT
Hello Jean-Guy and Jay,

Thank you each for your responses.  It looks like there is some potential in
that link you sent, although it appears to be a work-around.  Pasting to the
document and then cutting from the paste can be problematic.  Still, both
posts are very helpful.  Jean-Guy asked what I am trying to do.  It is this.
I need to be able to read, sort, and print the TA field so I can create my
own Table of references, in my own design.  This means that I need to be able
to read the text (with formatting) into an array, sort the array, eliminate
duplicates, and print the modified array.  So far, all the text manipulation
code in VBA brings along the characters, but leaves off italic formatting.

I look forward to your thoughts.

keith  

> keith was telling us:
> keith nous racontait que :
[quoted text clipped - 23 lines]
>
> What are you trying to do?
Jean-Guy Marcil - 06 Jul 2005 18:23 GMT
keith was telling us:
keith nous racontait que :

> Hello Jean-Guy and Jay,
>
[quoted text clipped - 9 lines]
> text manipulation code in VBA brings along the characters, but leaves
> off italic formatting.

But, even if you copy the text into the clipboard, as soon as you sort it
through the array variable, you will lose formatting anyway.
How does the clipborad help in this case?

Why not read the code from the TA field and modify it so it outputs what you
want?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jay Freedman - 06 Jul 2005 18:30 GMT
Hi Keith,

As I said, hacking the clipboard is often not the preferable way of solving
a problem. Knowing the overall objective helps in selecting a better method.

In your case, I would create a separate blank document as a scratch pad.
Declare and define two Range objects, one in the source document and one in
the scratch pad document. Set the source range to cover the first piece of
desired text (whether by its style, by its content or location, or from the
Selection). Then use a statement like this:

  DestRange.FormattedText = SourceRange.FormattedText

to copy both the text and the formatting of the  source into the
destination. This doesn't use the clipboard at all!

Now collapse the destination range and move it to the end of the scratch
pad, insert a paragraph mark there, move the source range to the next piece
of text in the original document, and repeat... until all needed text has
been copied.

Finally, sort the scratch pad, delete the duplicates, and print. You can
save the scratch pad as a separate document, discard it, or copy the
FormattedText of the entire scratch pad into a range in the original
document.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hello Jean-Guy and Jay,
>
[quoted text clipped - 48 lines]
>> jmarcilREMOVE@CAPSsympatico.caTHISTOO
>> Word MVP site: http://www.word.mvps.org
keith - 06 Jul 2005 18:55 GMT
Hello Jay and Jean-Guy

Thank you again for your responses.  I'm going to need to study these for a
while to work through the details.  Although I have been thinking about going
through this extended VBA solution to the problem I face, maybe one of you
knows an easier solution to the root issue.  The root problem is that I can
create a TA in the APA (American Psychological Association) required style.  
However, when try to print the table of autorities, Word includes both a
dotted tab and a page number.  I can turn off the dotted tab, but not the
page number.  APA Style requires that there not be either a dotted tab or a
page number.  Is there any way to use VBA to turn off the page number?

Keith

> Hi Keith,
>
[quoted text clipped - 74 lines]
> >> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> >> Word MVP site: http://www.word.mvps.org
Jean-Guy Marcil - 06 Jul 2005 19:29 GMT
keith was telling us:
keith nous racontait que :

> Hello Jay and Jean-Guy
>
[quoted text clipped - 9 lines]
> a page number.  Is there any way to use VBA to turn off the page
> number?

If you are not using categories, you could use a TOC field with TC fields
instead. TC fields allow a switch that suppresses page numbering, TA fields
don't.

You could still have the regular TOC based on outlining, and your TOA would
in fact be a TOC based on TC fields.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

keith - 06 Jul 2005 19:39 GMT
Hi Jean-Guy
Thank you
I'll take a look at that option.  Looks promising.
keith

> keith was telling us:
> keith nous racontait que :
[quoted text clipped - 19 lines]
> You could still have the regular TOC based on outlining, and your TOA would
> in fact be a TOC based on TC fields.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.