Vista behaves differently to WordBasic command even though same version of Word!

L

Laphan

Hi All

My setup is VB6 app to Ms Word doc and basically it took me 5+ hours to get
my app to pre-populate the Save/SaveAs filename of a word doc so that when
the user has looked at the doc, found it to be OK and then clicked either
File/Save or File/SaveAs the filename is done for them.

I couldn't use the BuiltInProperties.... feature as it doesn't work when
called from an external VB6 app - is this still correct?

Somebody kindly enlightened me about the use of WordBasic and the following
command works fine in XP SP2 with Office 2000/XP/2003 (not tried 2007 yet):

oWord.WordBasic.SetDocumentProperty "Title", 0, strMyFileName, 1

Problem is I've just run the exact same app on a Vista machine running
Office 2003 and I get sort of 2 copies of the doc. One is the usual titled
Document1, as I'm pulling a Word template everytime, but when you close this
doc (ie don't bother saving it) you find another copy of the doc behind it,
but this one has the title of the Word template itself!!

Does anybody know if the BuiltInProperties.... bit works in Vista?

or

Does anybody know how I can stop this dual doc creation?

or

Does anybody know how I can just run the above WordBasic command if the OS
is XP?

Many thanks.
 
L

Lorin

Sorry.
I get dual docs when trying to create a PDF from some sources using Adobe
Creator. Maybe related in the OS somehow? I see it on XP (latest updates).
 
M

MikeD

Laphan said:
Hi All

My setup is VB6 app to Ms Word doc and basically it took me 5+ hours to
get
my app to pre-populate the Save/SaveAs filename of a word doc so that when
the user has looked at the doc, found it to be OK and then clicked either
File/Save or File/SaveAs the filename is done for them.

I couldn't use the BuiltInProperties.... feature as it doesn't work when
called from an external VB6 app - is this still correct?

Somebody kindly enlightened me about the use of WordBasic and the
following
command works fine in XP SP2 with Office 2000/XP/2003 (not tried 2007
yet):

oWord.WordBasic.SetDocumentProperty "Title", 0, strMyFileName, 1

Problem is I've just run the exact same app on a Vista machine running
Office 2003 and I get sort of 2 copies of the doc. One is the usual
titled
Document1, as I'm pulling a Word template everytime, but when you close
this
doc (ie don't bother saving it) you find another copy of the doc behind
it,
but this one has the title of the Word template itself!!

Does anybody know if the BuiltInProperties.... bit works in Vista?

or

Does anybody know how I can stop this dual doc creation?

or

Does anybody know how I can just run the above WordBasic command if the OS
is XP?

Many thanks.


Why are you using WordBasic at all? AFAIK, WordBasic hasn't really been used
in Word since Word95. Out of curiosity, I checked the Help in Word 2007.
After some digging, I did find reference to the WordBasic property, which
basically (no pun intended) confirmed what I suspected. First line is:

"Returns an automation object (Word.Basic) that includes methods for all the
WordBasic statements and functions available in Word version 6.0 and Word
for Windows 95"

You should be using Automation. The Word object model has an Application
object which has a FileDialog property, which you can use to show the SaveAs
dialog box. Then, if you wanted, you could have code in your VB6 app to use
the Document object's SaveAs method to save the document using the path and
file name the user chose in the dialog box. If you dig into the
documentation for the Word object model, you can probably find a property of
some object in which you can pre-populate the SaveAs dialog when the user
open this manually.

Here's some example code that may be of help. This was written against Word
2007. My guess is that it should work fine with earlier versions of Word.
Since it uses early-binding, you'll need to add two references. One to the
"Microsoft Word xx Object Library" and another to "Microsoft Office xx
Object Library". The latter reference is only needed for the
msoFileDialogSaveAs constant. You could just declare the constant yourself
and not bother with the reference to the Office Object Library (the
constant's value is 2).

Dim oApp As Word.Application
Dim oDoc As Word.Document
Dim oFD As FileDialog

Set oApp = New Word.Application
oApp.Visible = True
Set oDoc = oApp.Documents.Add

Set oFD = oApp.FileDialog(msoFileDialogSaveAs)

With oFD
.InitialFileName = "test"
.Show
.Execute
End With

You can assign the file name to a variable, and use that variable as the
filename parameter of the SaveAs dialog. Use the SelectedItems property of
the FileDialog object, as such:

Dim sFileName As String
sFileName = oFD.SelectedItems(1)

Note that the Execute method saves the document, so for future saves you
really only need to use the Save method of the Document object. I realize
that this code is not quite what you appear to want to do since you seem to
want the user to show the SaveAs dialog rather than it being shown via your
code. The example is really just to be giving you an idea of what you should
be using instead of WordBasic.

For the record, while I had the Help open for Word 2007, I searched for both
BuiltInProperties and SetDocumentProperty....nothing found for either.
 
L

Laphan

Hi Guys

Thanks for getting back to me on this. Much appreciated.

I do appreciate what you're saying MikeD, but I need the process of
displaying the Word doc, but not displaying the SaveAs dialog or auto-saving
it to a location. The user needs to look over it and if all OK then go to
File/Save or File/SaveAs to save it where they need it to go. At this point
I need to pre-populate the filename to give them a helping hand as they are
using thousands of different file nomclatures, which in the long run isn't
hellping!

I tried for hours to get the new standard method to work, ie the
BulitinProperties.. command line, and finally found on a MVPS that the
command won't work from VB to Word. It will only work from within Word, ie
Word VBA.

If I could use something else other than WordBasic then I would :0)


Laphan said:
Hi All

My setup is VB6 app to Ms Word doc and basically it took me 5+ hours to
get
my app to pre-populate the Save/SaveAs filename of a word doc so that when
the user has looked at the doc, found it to be OK and then clicked either
File/Save or File/SaveAs the filename is done for them.

I couldn't use the BuiltInProperties.... feature as it doesn't work when
called from an external VB6 app - is this still correct?

Somebody kindly enlightened me about the use of WordBasic and the
following
command works fine in XP SP2 with Office 2000/XP/2003 (not tried 2007
yet):

oWord.WordBasic.SetDocumentProperty "Title", 0, strMyFileName, 1

Problem is I've just run the exact same app on a Vista machine running
Office 2003 and I get sort of 2 copies of the doc. One is the usual
titled
Document1, as I'm pulling a Word template everytime, but when you close
this
doc (ie don't bother saving it) you find another copy of the doc behind
it,
but this one has the title of the Word template itself!!

Does anybody know if the BuiltInProperties.... bit works in Vista?

or

Does anybody know how I can stop this dual doc creation?

or

Does anybody know how I can just run the above WordBasic command if the OS
is XP?

Many thanks.


Why are you using WordBasic at all? AFAIK, WordBasic hasn't really been used
in Word since Word95. Out of curiosity, I checked the Help in Word 2007.
After some digging, I did find reference to the WordBasic property, which
basically (no pun intended) confirmed what I suspected. First line is:

"Returns an automation object (Word.Basic) that includes methods for all the
WordBasic statements and functions available in Word version 6.0 and Word
for Windows 95"

You should be using Automation. The Word object model has an Application
object which has a FileDialog property, which you can use to show the SaveAs
dialog box. Then, if you wanted, you could have code in your VB6 app to use
the Document object's SaveAs method to save the document using the path and
file name the user chose in the dialog box. If you dig into the
documentation for the Word object model, you can probably find a property of
some object in which you can pre-populate the SaveAs dialog when the user
open this manually.

Here's some example code that may be of help. This was written against Word
2007. My guess is that it should work fine with earlier versions of Word.
Since it uses early-binding, you'll need to add two references. One to the
"Microsoft Word xx Object Library" and another to "Microsoft Office xx
Object Library". The latter reference is only needed for the
msoFileDialogSaveAs constant. You could just declare the constant yourself
and not bother with the reference to the Office Object Library (the
constant's value is 2).

Dim oApp As Word.Application
Dim oDoc As Word.Document
Dim oFD As FileDialog

Set oApp = New Word.Application
oApp.Visible = True
Set oDoc = oApp.Documents.Add

Set oFD = oApp.FileDialog(msoFileDialogSaveAs)

With oFD
.InitialFileName = "test"
.Show
.Execute
End With

You can assign the file name to a variable, and use that variable as the
filename parameter of the SaveAs dialog. Use the SelectedItems property of
the FileDialog object, as such:

Dim sFileName As String
sFileName = oFD.SelectedItems(1)

Note that the Execute method saves the document, so for future saves you
really only need to use the Save method of the Document object. I realize
that this code is not quite what you appear to want to do since you seem to
want the user to show the SaveAs dialog rather than it being shown via your
code. The example is really just to be giving you an idea of what you should
be using instead of WordBasic.

For the record, while I had the Help open for Word 2007, I searched for both
BuiltInProperties and SetDocumentProperty....nothing found for either.
 
D

Doug Robbins - Word MVP on news.microsoft.com

Once you have a proper reference to the Word Application and the Document
object, you should be able to use all Word VBA commands, including the
BuiltInDocumentProperties. That said, there are still somethings where an
old WordBasic. command is required.

What do you mean by "pulling a Word Template everytime"? Show us the code
that you are using so that we can try and replicate the issue.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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