AboutAidan Heritage Expertise I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for
all versions of Word from 2 onwards
Question QUESTION: Hi Aidan,
Is it possible, using a macro, to copy a selection of text in Word, create a new folder at a specific location, name the folder by pasting the copied text, then save the document to that location?
Thanks for any help you can give.
ANSWER: something like this
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 28/11/2007 by heritaa
'
Dim mywrd As Document
Dim mysel As Selection
Set mysel = Selection
Set mywrd = Application.Documents.Add
mywrd.Range.Text = mysel
Dim holder As String
holder = InputBox("which folder do you want to create?", "File Location", "C:\Temp\")
On Error Resume Next
MkDir holder
mywrd.SaveAs holder & "/" & "test.doc"
mywrd.Close
End Sub
---------- FOLLOW-UP ----------
QUESTION: Hi Aidan, thanks for your quick response, but I'm afraid I don't understand your answer. Can you dumb it down a bit for me? Do I copy and paste this into my macro?
What I'm trying to do is copy specific text in a document (that specific report's run date), then open a new folder and use the copied text to name the new folder, then save the document in that folder. The problem I'm running into is that I need the macro to copy different text each time (new report date every day) and use the specific text to name a new folder each time.
Thanks for your help.
Answer Thanks for the follow up - I gave you an entire macro, but it seems as though the macro wasn't the macro you wanted (my version creates a new document containing ONLY the selected text, then asks you what folder you want. The bit of the code you need therefore is
Dim holder As String
holder = activedocument.selection
On Error Resume Next
MkDir holder
activedocument.SaveAs holder & "/" & "test.doc"
'the line above will always give the file a name of test.doc
'it will also save in a folder from the CURRENT location, which is probably NOT what you had in mind
About Microsoft Word
This topic answers questions related to Microsoft Word stand-alone or Mircrosoft Office Word including Word 2003, Word 2007, Office 2000, and Office XP. You can get Word help on formatting text, tables, tabs, fonts, styles, general Word layouts, bullets, headings, and outlines, using templates, toolbar modifications, and using Track Changes. You may also find tips on linking Word and Excel embedded objects including charts. This site does not provide a general Word tutorial nor the basics of using a word processor. It provides specific answers to using Microsoft Word only. If you do not see your Word question answered in this area then please ask a Word question here