copying fullname to string variable & to clipboard, and typing it out

M

marc

I'm trying (vba) to copy the fullname to a msgbox, and to
a variable (strFulNam) and to the Clipboard, and to print
out the fullname.
My coding below doesn't work, except to show the
fullname in a msgbox.
Any help would be much appreciated.
Thanks,
Marc

Dim strFulNam As String
strFulNam = ActiveDocument.FullName
MsgBox ActiveDocument.FullName
Dim MyDataObj As New DataObject
MyDataObj.SetText strFulNam
MyDataObj.PutInClipboard
MyDataObj.GetFromClipboard
 
D

DA

Hi Marc

Your code is probably not working because you need a
reference set to the Microsoft Forms Object Library.
(To add this, click on "Tools>References" in your VBA
editor)

Here is a bit of code where you won't have to set those
kind of references. It uses the Selection object to get
the data into the clipboard, opens a new doc, pastes the
name, prints it, then closes that doc.

---------------------
Sub Show_n_Print_FullNam()

Dim strFulNam As String
strFulNam = ActiveDocument.FullName
MsgBox strFulNam
Selection.Text = strFulNam
Selection.Cut
Documents.Add
Selection.Paste
ActiveDocument.PrintOut
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End Sub
 
M

Marc Hankin

1. That was very helpful. Thank you.
2. Do you know where can I find a list of all the
arguments for the Selection object, with explanations for
them, i.e., how they work, what they require, etc.? I've
tried to find it in the VBA help file, and on Microsoft's
website, but I haven't been able to find it.
3. I'm hoping that by learning the Selection arguments,
I'll be able to figure out how to copy the fullname into
the Windows clipboard...without pasting it onto a
document. (My subsequent challenge to myself will be to
delete [from any such text] the outline number and the tab
or spacess following the number, and thereafter to paste
the text as unformatted text into a document. I'm not
asking you to do this work for me, I just couldn't help
sharing where I'm going with this, in case you find it
interesting to see how a newbie plans to grow in vba
programming.)

Thanks again,

marc
 
D

DA

Hi Marc

Nice thing about the VBA environment is that you'll get
the list of Members for a Class pop up automatically if
you enable "Autolist Members" in your options.

As with anything, it just takes time and practice to work
out how the whole thing hangs together.

This forum is an excellent way of getting past any
hurdles in your journey to learn VBA. There are lots of
very knowledgeable and friendly professionals here, so
don't be afraid to ask for help on things.

In case you haven't been there already, also check out
the Word MVP site (http://word.mvps.org/index.html).
There are a heap of other links and books worth reading,
but the MVP site will be a great starting point.

All the best,
Dennis
-----Original Message-----
1. That was very helpful. Thank you.
2. Do you know where can I find a list of all the
arguments for the Selection object, with explanations for
them, i.e., how they work, what they require, etc.? I've
tried to find it in the VBA help file, and on Microsoft's
website, but I haven't been able to find it.
3. I'm hoping that by learning the Selection arguments,
I'll be able to figure out how to copy the fullname into
the Windows clipboard...without pasting it onto a
document. (My subsequent challenge to myself will be to
delete [from any such text] the outline number and the tab
or spacess following the number, and thereafter to paste
the text as unformatted text into a document. I'm not
asking you to do this work for me, I just couldn't help
sharing where I'm going with this, in case you find it
interesting to see how a newbie plans to grow in vba
programming.)

Thanks again,

marc

-----Original Message-----
Hi Marc

Your code is probably not working because you need a
reference set to the Microsoft Forms Object Library.
(To add this, click on "Tools>References" in your VBA
editor)

Here is a bit of code where you won't have to set those
kind of references. It uses the Selection object to get
the data into the clipboard, opens a new doc, pastes the
name, prints it, then closes that doc.

---------------------
Sub Show_n_Print_FullNam()

Dim strFulNam As String
strFulNam = ActiveDocument.FullName
MsgBox strFulNam
Selection.Text = strFulNam
Selection.Cut
Documents.Add
Selection.Paste
ActiveDocument.PrintOut
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End Sub
---------------------

Hope that helps,
Dennis

.
.
 
M

Marc Hankin

Dear Dennis
Thanks for the encouraging reply and the referral to
the MVP site. I'll do some more nosing around there.
I enabled the "Autolist Members" in my options, and
that is helpful, but I'm still mystified by the lengthy
list of options.
1. I wish I could find something like the "pages" in the
VBA help file for all those arguments for the selection
object, e.g., a page for each argument, explaining it,
giving examples showing how to use it, along with the
typical "See also" references to related stuff.
2. I wish I could figure out how to print out the entire
help file, so that I could read it more easily.
Thanks again. The help you give and the encouragement
are heartwarming. I'm a "self-appointed" public interest
lawyer (who does more pro bono than I can afford, all in
the elder abuse area). I see so much indifference to
human suffering that your charity in helping me (and
others) is "chicken soup for the soul". My compliments
to you and your colleagues.
Kindest regard,
Marc
-----Original Message-----
Hi Marc

Nice thing about the VBA environment is that you'll get
the list of Members for a Class pop up automatically if
you enable "Autolist Members" in your options.

As with anything, it just takes time and practice to work
out how the whole thing hangs together.

This forum is an excellent way of getting past any
hurdles in your journey to learn VBA. There are lots of
very knowledgeable and friendly professionals here, so
don't be afraid to ask for help on things.

In case you haven't been there already, also check out
the Word MVP site (http://word.mvps.org/index.html).
There are a heap of other links and books worth reading,
but the MVP site will be a great starting point.

All the best,
Dennis
-----Original Message-----
1. That was very helpful. Thank you.
2. Do you know where can I find a list of all the
arguments for the Selection object, with explanations for
them, i.e., how they work, what they require, etc.? I've
tried to find it in the VBA help file, and on Microsoft's
website, but I haven't been able to find it.
3. I'm hoping that by learning the Selection arguments,
I'll be able to figure out how to copy the fullname into
the Windows clipboard...without pasting it onto a
document. (My subsequent challenge to myself will be to
delete [from any such text] the outline number and the tab
or spacess following the number, and thereafter to paste
the text as unformatted text into a document. I'm not
asking you to do this work for me, I just couldn't help
sharing where I'm going with this, in case you find it
interesting to see how a newbie plans to grow in vba
programming.)

Thanks again,

marc

-----Original Message-----
Hi Marc

Your code is probably not working because you need a
reference set to the Microsoft Forms Object Library.
(To add this, click on "Tools>References" in your VBA
editor)

Here is a bit of code where you won't have to set those
kind of references. It uses the Selection object to get
the data into the clipboard, opens a new doc, pastes the
name, prints it, then closes that doc.

---------------------
Sub Show_n_Print_FullNam()

Dim strFulNam As String
strFulNam = ActiveDocument.FullName
MsgBox strFulNam
Selection.Text = strFulNam
Selection.Cut
Documents.Add
Selection.Paste
ActiveDocument.PrintOut
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End Sub
---------------------

Hope that helps,
Dennis

-----Original Message-----
I'm trying (vba) to copy the fullname to a msgbox, and
to
a variable (strFulNam) and to the Clipboard, and to
print
out the fullname.
My coding below doesn't work, except to show the
fullname in a msgbox.
Any help would be much appreciated.
Thanks,
Marc

Dim strFulNam As String
strFulNam = ActiveDocument.FullName
MsgBox ActiveDocument.FullName
Dim MyDataObj As New DataObject
MyDataObj.SetText strFulNam
MyDataObj.PutInClipboard
MyDataObj.GetFromClipboard
.

.
.
.
 
C

Chad DeMeyer

Marc,

The next trick to learn if you haven't already is "context-sensitive help".
So if you type the name of an object in the code window (or in the Immediate
window), with your cursor in or at the end of the word press F1 to get the
help topic for that object (e.g., Selection). On the object topic page are
link categories, which may include Properties of the object, Methods of the
object, See Also links, and more. Many of the help topics contain links to
examples which show a practical application of the topic in real code. You
can also type the dot separator after an object, or a property or method
which returns an object, then select one of the members in the autolist, and
then press F1 for specific help on that member. Not quite like reading a
book, but after a while it does start to feel intuitive.

Regards,
Chad


Marc Hankin said:
Dear Dennis
Thanks for the encouraging reply and the referral to
the MVP site. I'll do some more nosing around there.
I enabled the "Autolist Members" in my options, and
that is helpful, but I'm still mystified by the lengthy
list of options.
1. I wish I could find something like the "pages" in the
VBA help file for all those arguments for the selection
object, e.g., a page for each argument, explaining it,
giving examples showing how to use it, along with the
typical "See also" references to related stuff.
2. I wish I could figure out how to print out the entire
help file, so that I could read it more easily.
Thanks again. The help you give and the encouragement
are heartwarming. I'm a "self-appointed" public interest
lawyer (who does more pro bono than I can afford, all in
the elder abuse area). I see so much indifference to
human suffering that your charity in helping me (and
others) is "chicken soup for the soul". My compliments
to you and your colleagues.
Kindest regard,
Marc
-----Original Message-----
Hi Marc

Nice thing about the VBA environment is that you'll get
the list of Members for a Class pop up automatically if
you enable "Autolist Members" in your options.

As with anything, it just takes time and practice to work
out how the whole thing hangs together.

This forum is an excellent way of getting past any
hurdles in your journey to learn VBA. There are lots of
very knowledgeable and friendly professionals here, so
don't be afraid to ask for help on things.

In case you haven't been there already, also check out
the Word MVP site (http://word.mvps.org/index.html).
There are a heap of other links and books worth reading,
but the MVP site will be a great starting point.

All the best,
Dennis
-----Original Message-----
1. That was very helpful. Thank you.
2. Do you know where can I find a list of all the
arguments for the Selection object, with explanations for
them, i.e., how they work, what they require, etc.? I've
tried to find it in the VBA help file, and on Microsoft's
website, but I haven't been able to find it.
3. I'm hoping that by learning the Selection arguments,
I'll be able to figure out how to copy the fullname into
the Windows clipboard...without pasting it onto a
document. (My subsequent challenge to myself will be to
delete [from any such text] the outline number and the tab
or spacess following the number, and thereafter to paste
the text as unformatted text into a document. I'm not
asking you to do this work for me, I just couldn't help
sharing where I'm going with this, in case you find it
interesting to see how a newbie plans to grow in vba
programming.)

Thanks again,

marc


-----Original Message-----
Hi Marc

Your code is probably not working because you need a
reference set to the Microsoft Forms Object Library.
(To add this, click on "Tools>References" in your VBA
editor)

Here is a bit of code where you won't have to set those
kind of references. It uses the Selection object to get
the data into the clipboard, opens a new doc, pastes the
name, prints it, then closes that doc.

---------------------
Sub Show_n_Print_FullNam()

Dim strFulNam As String
strFulNam = ActiveDocument.FullName
MsgBox strFulNam
Selection.Text = strFulNam
Selection.Cut
Documents.Add
Selection.Paste
ActiveDocument.PrintOut
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End Sub
---------------------

Hope that helps,
Dennis

-----Original Message-----
I'm trying (vba) to copy the fullname to a msgbox, and
to
a variable (strFulNam) and to the Clipboard, and to
print
out the fullname.
My coding below doesn't work, except to show the
fullname in a msgbox.
Any help would be much appreciated.
Thanks,
Marc

Dim strFulNam As String
strFulNam = ActiveDocument.FullName
MsgBox ActiveDocument.FullName
Dim MyDataObj As New DataObject
MyDataObj.SetText strFulNam
MyDataObj.PutInClipboard
MyDataObj.GetFromClipboard
.

.

.
.
 
J

Jonathan West

Marc Hankin said:
1. That was very helpful. Thank you.
2. Do you know where can I find a list of all the
arguments for the Selection object, with explanations for
them, i.e., how they work, what they require, etc.? I've
tried to find it in the VBA help file, and on Microsoft's
website, but I haven't been able to find it.

Position the curstor over the word "Selection" in the VBA editor, and press
the F1 key. The help entry for the selection object should appear. This will
list all the properties and methods of the Selection.

3. I'm hoping that by learning the Selection arguments,
I'll be able to figure out how to copy the fullname into
the Windows clipboard...without pasting it onto a
document. (My subsequent challenge to myself will be to
delete [from any such text] the outline number and the tab
or spacess following the number, and thereafter to paste
the text as unformatted text into a document. I'm not
asking you to do this work for me, I just couldn't help
sharing where I'm going with this, in case you find it
interesting to see how a newbie plans to grow in vba
programming.)

You can put any arbitrary string directly into the clipboard by the method
described in this article

Manipulating the clipboard using VBA
http://word.mvps.org/FAQs/MacrosVBA/ManipulateClipboard.htm
 
J

Jonathan West

Marc Hankin said:
Dear Dennis
Thanks for the encouraging reply and the referral to
the MVP site. I'll do some more nosing around there.
I enabled the "Autolist Members" in my options, and
that is helpful, but I'm still mystified by the lengthy
list of options.
1. I wish I could find something like the "pages" in the
VBA help file for all those arguments for the selection
object, e.g., a page for each argument, explaining it,
giving examples showing how to use it, along with the
typical "See also" references to related stuff.
2. I wish I could figure out how to print out the entire
help file, so that I could read it more easily.

Take a look here

Microsoft Office 2000/Visual Basic Programmer's Guide
http://msdn.microsoft.com/library/d...000visualbasicprogrammersguide.asp?frame=true

In particular, within chapter 5, take a look here

Working with Microsoft Word Objects
http://msdn.microsoft.com/library/en-us/odeopg/html/deovrworkingwithmicrosoftwordobjects.asp

You can't print it all off in one go, but you can at least go sequentially
from topic to topic
 

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