Programmatically setting the Save As filename in a Word doc via VB6

L

Laphan

Hi All

First of all I know the SaveAs command would enable me to pre-set the
filename of a word doc, but unfortunately it will auto save it somewhere and
this won't do in my case.

A perfect solution for me is that the Word doc appears (from a word template
I have created so it's a fresh copy with a bit of dynamic data every time)
and when the user goes to File / Save or File / Save As a pre-defined
(dynamically put together) filename is already in the box so 9/10 they can
just find the location that they want to save it and click Save.

I cannot do SaveAs because the user must have the ability to go and put it
in a particular location. Each user will definetely save it in a different
location to another user.

I have tried:

ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = "My title"

but it doesn't change the filename in the Save dialogue.

I have tried various combos using the below:

With Dialogs(wdDialogFileSummaryInfo)
.Title = "My Title"
.Execute
End With

For example, I tried it as is, but this just doesn't work when you run it.
I started to type oWord.Dialogs(wdDialogFileSummaryInfo), but I didn't get
..Title in the Intellisense and when I type it literally it still doesn't
work.

I've seen something called FileDialog, but when you enter the
(msoFileSaveAs).InitialFilename bit it run time errors.

Am I right in saying that what I want to do is not possible?

Has anybody found a fudge/botch/cludge to get round this?

I don't want to do SaveAs and then say to the user that by the way there
will be a million unnecessary word docs in your My Docs because I needed to
do this to pre-populate the box.

Any ideas?

Happy New Year by the way!!
 
H

Helmut Weber

Hi Laphan,

something along these lines:

Sub Test556()
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogFileSaveAs)
With oDlg
.name = "c:\test\MyTest2.doc"
.Show
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
L

Laphan

Hi Helmut

Many thanks for getting back to me, but this doesn't work.

VB just doesn't bring up the same properties when you go oDlg.<no name bit
available>

I actually don't get to this bit as it falls foul on the Set bit with a
document not active error.

Any ideas?

Rgds



Hi Laphan,

something along these lines:

Sub Test556()
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogFileSaveAs)
With oDlg
.name = "c:\test\MyTest2.doc"
.Show
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
J

Jonathan West

Laphan said:
Hi Helmut

Many thanks for getting back to me, but this doesn't work.

VB just doesn't bring up the same properties when you go oDlg.<no name bit
available>

It won't. But if you type them, the code will run.
I actually don't get to this bit as it falls foul on the Set bit with a
document not active error.

That suggests that there is no document open at the time that you run the
macro. You can't save a document unless you have a document open which can
be saved.
 
L

Laphan

Hi Jonathan

Thanks for your reply, but I think I'm confusing matters.

I am calling, populating and then trying to affect the default filename of
the doc all from VB.

My code is currently as follows:

Set oWord = New Word.Application
Set oNewDoc = oWord.Documents.Add(App.Path & "\data\progress-inits.dot")

<add some text to the word doc .... this bit works fine so chopped it for
clarity>

oWord.Visible = True
oWord.Activate

Set oDoc = Nothing
Set oNewDoc = Nothing
Set oWord = Nothing

The word doc is presented in front of my VB app so that the user can check
it over to make sure all is OK and then the next process would be that they
would go to File / Save or File / Save As (both are the same in this
instance as I'm using a child of a Word template) and at this stage I want
the default filename to be one that I've generated.

Can this be done???

Thanks



Laphan said:
Hi Helmut

Many thanks for getting back to me, but this doesn't work.

VB just doesn't bring up the same properties when you go oDlg.<no name bit
available>

It won't. But if you type them, the code will run.
I actually don't get to this bit as it falls foul on the Set bit with a
document not active error.

That suggests that there is no document open at the time that you run the
macro. You can't save a document unless you have a document open which can
be saved.
 
H

Helmut Weber

Hi Laphan.

you might like to redefine the filesaveas dialog:

Sub FileSaveAs()
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogFileSaveAs)
With oDlg
.name = "C:\test\test.doc"
.Show
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
L

Laphan

Hi Helmut

Sorry I don't get what you mean.

The below looks exactly the same as your previous suggestion, but in a sub
called FileSaveAs.

How will this make the diff??

Thanks


Hi Laphan.

you might like to redefine the filesaveas dialog:

Sub FileSaveAs()
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogFileSaveAs)
With oDlg
.name = "C:\test\test.doc"
.Show
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
G

Graham Mayor

Helmut

Just hijacking the thread to ask if you know of a similar method of putting
an address in the envelope dialog?

Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogToolsCreateEnvelope)
With oDlg
?????
.Show
End With


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Helmut Weber

Hi Laphan,
Sorry I don't get what you mean.

The below looks exactly the same as your previous suggestion, but in a sub
called FileSaveAs.

How will this make the diff??

the differnce is, that whenever
a user clicks the button filesaveas,
the predefined name will show.
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
H

Helmut Weber

Hi Graham,
Just hijacking the thread to ask if you know of a similar method of putting
an address in the envelope dialog?
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogToolsCreateEnvelope)
With oDlg
?????
.Show
End With

not the faintest idea.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
L

Laphan

I apologise for being thick here, but are you saying that if I create a sub
in my VB app's form IDE window called FileSaveAs then when the user goes to
File / Save As in Word it will look at the procedure in my VB app rather
than anything in the actual Word doc?


Hi Laphan,
Sorry I don't get what you mean.

The below looks exactly the same as your previous suggestion, but in a sub
called FileSaveAs.

How will this make the diff??

the differnce is, that whenever
a user clicks the button filesaveas,
the predefined name will show.
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
T

Tony Jollans

What about this?

WordBasic.SetDocumentProperty "Title", 0, "Your Default SaveAs Name", 1
 
G

Graham Mayor

Brilliant. Thanks :)
Do you know where such matters are documented?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Good man :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Helmut Weber

Hi Laphan
I apologise for being thick here, but are you saying that if I create a sub
in my VB app's form IDE window called FileSaveAs then when the user goes to
File / Save As in Word it will look at the procedure in my VB app rather
than anything in the actual Word doc?

indeed.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
L

Laphan

Sorry Helmut, but having done it VB6 connecting to a Word 2003 doc nothing
happend.

Thanks anyway.

Rgds


Hi Laphan
I apologise for being thick here, but are you saying that if I create a sub
in my VB app's form IDE window called FileSaveAs then when the user goes to
File / Save As in Word it will look at the procedure in my VB app rather
than anything in the actual Word doc?

indeed.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
L

Laphan

Hi Tony

Where did this gem come from????

How come nobody (and I mean nobody!) knows about this command???

Is it compatible with Word 2000, 2003 and 2007?

Thanks a mill

"Tony Jollans" <My forename at my surname dot com> wrote in message
What about this?

WordBasic.SetDocumentProperty "Title", 0, "Your Default SaveAs Name", 1
 
H

Helmut Weber

Hi Laphan,
Sorry Helmut, but having done it VB6 connecting to a Word 2003 doc nothing
happend.

Thanks anyway.

Rgds

sorry, your subject was too long for my newsreader
to show me that is was about VB 6.
All I saw was:
"Programmatically setting the Save As filename..."

What I wanted to suggest was
creating a FileSaveAs macro in Word, not in the VB 6 application.
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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