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 / May 2006

Tip: Looking for answers? Try searching our database.

Automating write to file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dudley - 06 May 2006 18:26 GMT
I have a macro which partially automates writing a document to file. It
copies text from the document to provide the output file name and then starts
write to file, but I do not know how to word a VBA instruction to paste text
from the clipboard to the outputfilename. Can anyone help?

Thanks
Dudley
Helmut Weber - 06 May 2006 19:16 GMT
Hi Dudley,

like this:

Sub Macro2()
Dim sTmp As String
Dim oClp As DataObject
Set oClp = New DataObject
oClp.GetFromClipboard
sTmp = oClp.GetText
MsgBox sTmp
End Sub

You need a reference to the Microsoft Forms 2.0 Library.

The odd thing, at least with the versions of Word I know,
is that you can't set a reference to the library in user interface.
Instead, you have to insert a userform.
The reference comes with the userform.
You may, after saving, remove the userform.
The reference will stay.

Strange, but that's the way it is.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Jezebel - 06 May 2006 23:11 GMT
If the information is coming from the document, there are simpler and better
ways than using the clipboard to get that information into a variable for
use as a filename.

eg

Dim pFileName as string
pFileName = "C:\MyDocuments\MyFolder\" & Selection & ".txt"

>I have a macro which partially automates writing a document to file. It
> copies text from the document to provide the output file name and then
[quoted text clipped - 5 lines]
> Thanks
> Dudley
Dudley - 07 May 2006 13:41 GMT
Thanks very much to Helmut and Jezebel. In this case I can get Helmut's
solution to work but not Jezebel's as the filename includes a mailmerge field
and entering this directly into a string is beyond my skills.

Regards
Dudley

> If the information is coming from the document, there are simpler and better
> ways than using the clipboard to get that information into a variable for
[quoted text clipped - 14 lines]
> > Thanks
> > Dudley
 
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.