Automatically naming documents after creating them?

I'm looking to make a macro that automatically creates a new document, then names it based on the values from a textbox. It would be called upon submission of the textbox. Ideally, it would name the doc "TB1.Value, TB2.Value, TB3.Value" obviously filling the actual values for all of those? Is there a way to do this? Currently I just use the following-

Dim newDoc As Document

Set newDoc = CreateDocument

not sure if there's a way to add naming to this. Any help would be great! Thanks

  • If you were having the macro create and save the file, then the naming would be part of the "SaveAs" operation.

    If you want to create a new document without saving it, but want to set what the Title is for the document, then you could do that by using CreateDocumentEx, and setting the name in the associated StructCreateOptions.

    Sub new_doc_named()
    Dim opt As New StructCreateOptions
        opt.Name = "foo"
        CreateDocumentEx opt
    End Sub
Reply Children
  • This works great! I do not need to save them. Is it possible to have the opt.Name = pull from the textboxes? So if TB1= AA, TB2=BB and TB3=CC, the name would be AA BB CC?

    Sure. In my example, I used the string, "foo". Use any string you like, as long as it's valid to use for a filename. In your case, you can put a string together using the contents of your textboxes.