How to use a text in a document as a filename...

J

Joost Nicasie

(tried to post this one through Google, but apparently that did not
work...)

Hi,

I've got one big document which I want to split up in all seperate
documents. I've found already a nice macro that does the trick...
but...

In each split document there's a remark: "save this as
thisandthat.txt"... so how do I make this macro use *those* filenames
instead of generated ones like file1, file2 etc..?

TIA,
Joost
 
A

Alex Ivanov

Joost,
Try something like this,

Dim r As Range
Dim fname As String
Set r = ActiveDocument.Range 'Set your own range
With r.Find
.Text = "save this as "
If .Execute Then
r.Collapse wdCollapseEnd
'assuming " is the delimiter
r.MoveEndUntil """", wdForward
fname = .Text
Else
MsgBox "Can't Find Filename"
End If
End With

HTH,
Alex.
 
J

Joost Nicasie

Hi Alex,

Forgive me my ignorance, but:
Dim r As Range
Dim fname As String
Set r = ActiveDocument.Range 'Set your own range
With r.Find
.Text = "save this as "
If .Execute Then
r.Collapse wdCollapseEnd
'assuming " is the delimiter
r.MoveEndUntil """", wdForward
fname = .Text
Else
MsgBox "Can't Find Filename"
End If
End With

the result of this is, that fname = "save this as"... instead of
"myfilename"... What am I doing wrong?

Or do I have to add something to the 'Set r =
ActiveDocument.Range'-line?

Cheers,
Joost

--
"I believe the light that shines on you
Will shine on you forever
And though I can't guarantee
There's nothing scary hiding under your bed
I’m gonna stand guard
Like a postcard of a Golden Retriever"
--Paul Simon
 
A

Alex Ivanov

'assuming " is the delimiter from your original post.
In your case it may be vbCr, space, tab, whatever... change the next line
accordingly.
 

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