Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Word Document - but name it 3

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Is there a way to add a document in word, but instead of it appearing titled as Document1, have a generated title. A luxury would be to have the name inserted in the dialogue box when asked if you want to save the document. I have not tried - Add as XXXX.Doc, that would be to logical and from experience so far, nothings logical in programming. Thanks
 
Are you writing this as an app, or as a piece of vb within word? Could you save the document under your name? This way it is already named, and appears so, then the user simply clicks save and its done. If however your user chooses to save as something else, then you can write a sub to delete the previously saved version under the name you gave it.

BB
 
Thanks, yes its a vb application that opens Word from scratch, always appears as Document 1. Its not a template, its just added as a document. My app then fills it. The user will never need to save it as a name other than whats generated for it. Word Application is not shelled, and I dont use the CreateObject method, just documnets add. Thanks
 
I take it you're using Documents.Add to generate the new doc. You can just do a SaveAs immediately after adding the doc:

In a module:

Public wordapp As Word.Application
Public worddoc As Word.Document

When you want your doc:

Set worddoc = wordapp.Documents.Add
worddoc.SaveAs (App.Path & "\" & docname)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Thanks Johnwm, good idea, but the trouble is there may be several times the document is opened before its wanted to be saved. If I could overcome the "Document already exists bit" so the user never knew what it was doing each time, then I could use your idea. ?? Is that easy? Or does Word overwrite without warning??. Aha ha, just tried it and it doesn't, so thats solved it. A star for you, thanks.
 
I just test for existence, then decide whether to open or add:

strDocName = App.Path & "\" & docname
If Len(Dir(strDocName)) > 0 Then
Set worddoc = wordapp.Documents.Open(strDocName)
Else
Set worddoc = wordapp.Documents.Add
worddoc.SaveAs (strDocName)
End If

Obviously also needs error checking etc.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Brilliant, many thanks again. Sorry I can't give another star. Regards
 
Thank you, ZOR (and whoever else found it helpful)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Fear not, Zor, I'll provide that extra star.

Thanks, John. Great Tip!

Of all the things I've lost, I miss my mind the most!
Sideman
 
Thanks Sideman for adding the star, sure John will aprreciate it. Regards
 
Thanks to you all! Much appreciated!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top