Automating write to file

D

Dudley

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
 
H

Helmut Weber

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.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Jezebel

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"
 
D

Dudley

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
 

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