is there a way to change flname = ActiveDocument.Name to select thedefault name in the 'save as' tex

T

Tenzen Raiden

I'm having a hard time running a macro which performs a certain number of actions and then copies a certain block text and pastes it onto a new sheet and saves it as a new document

everything works fine except for the naming. when i recorded the Macro, it just kept overwriting the same file with the same file name from the first instance of the macro. ...

After much searching i modified the macro to use "flname" to save as "ActiveDocumentName" the problem is that each document is simply named by Word as "Document2", "Document3", etc

I even tried to record my macro in the Save Dialog Box itself, using highlight, backspacing over the extension, and copying the file name, then selecting the File type and pasting the new name and saving it, but still it simply wrote the name of the first file name to the macro script

when you open a save box in Word, the default name is the first few words of text, and its even written in the save dialogue box, but no matter what I tried, the macro simply doesnt record that information, and just writes the name of the first instance into the code

I've looked everywhere for a solution, but i cant find anything

can anyone tell me how to modify this section of the macro to change flname to something to do with the name word automatically offers in the save box, without simply writing the first title into the code?

this one names them consecutively "Document 21" etc..:

flname = ActiveDocument.Name
ActiveDocument.SaveAs FileName:=flname & ".rtf", FileFormat:=wdFormatRTF, _


and this is my original one which just kept the same name and overwrote the same file over and over without creating any new files. the content changed, but the name stayed the same, meaning only one file was ever created

ActiveDocument.SaveAs FileName:="CoolNameHere.rtf", FileFormat:=wdFormatRTF, _

the purpose of this script is to take segments out of a very large word document and save them as individual rtf files i'm basically just looking for a small bit of text to put between:

Selection.PasteAndFormat (wdPasteDefault)

and (your awesome naming solution here)

LockComments:=False, Password:="",


i'm thinking its just changing flname = ActiveDocument.Name

i think i could just use flname = and then use something like DefaultText.Name or something similar

flname = DefaultText.Name

or

flname = Default.Name


or
flname = ActiveTextBox.Name

or

flname = FirstLine.Name

or

flname = ActiveDialog.Name

or

flname = SaveDialog.Name

etc there must be another term i could use to select what just defaults in the Save Box

Or I could also maybe run a macro to convert the same line of text with "Title" (ex.) in it, into a "heading" perhaps, or some other type of reference-able item if there were a naming macro which could used that title or heading or index etc info as the file name when saving


any help would be greatly appreciated.

here is the full script: thanks


Sub SeparateFiles()
'
' SeparateFiles Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find
..Text = "Title"
..Replacement.Text = "Title"
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchByte = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.Extend
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
..Text = "Title"
..Replacement.Text = "Title"
..Forward = True
..Wrap = wdFindAsk
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchByte = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.Copy
Application.Move Left:=0, Top:=0
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
flname = ActiveDocument.Name
ActiveDocument.SaveAs FileName:=flname & ".rtf", FileFormat:=wdFormatRTF, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ActiveWindow.Close
Selection.EscapeKey
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
 

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

Similar Threads


Top