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

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.



Fri, 19 Aug 2011 03:10:58 GMT  
 Vista behaves differently to WordBasic command even though same version of Word!


Quote:
> 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.

--
Mike



Fri, 19 Aug 2011 06:08:40 GMT  
 Vista behaves differently to WordBasic command even though same version of Word!
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)



Quote:
> 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.

--
Mike



Fri, 19 Aug 2011 17:43:48 GMT  
 Vista behaves differently to WordBasic command even though same version of Word!
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


Quote:
> 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)





>> 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.

> --
> Mike



Sat, 20 Aug 2011 03:26:41 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Why does a multipage control behave differently in VB5/6 to the VBA version

2. vba behave differently in ver. 9.038 and 9.044

3. AdvancedSearch behaves differently on different computers

4. Contacts behave differently in Public Folders and Mailboxes

5. DBList32.OCX control behaving differently in VB6 compared to VB5

6. Objects behave differently when started from ASP?

7. VB4/Win95 - Shell function behaves differently

8. Help Newbie...application behaves differently on user machine

9. Timer controls behave differently in development and executable

10. EXE behaves differently

11. Forms in COM Component behave differently when called from VB6 or VC++6 Apps

12. I upgraded to IE6 and my code behaves differently

 

 
Powered by phpBB® Forum Software