PDA

View Full Version : Looking for a WordBasic equivalent



island17
10-24-2008, 09:30 AM
I'm trying to replicate a word basic macro in VBA. Does anyone know what would be the equivalent to (WordBasic.FormatStyleGallery Template:="Normal").

fumei
10-24-2008, 10:40 AM
Perhaps, if you tell us what it is supposed to do.

island17
10-24-2008, 12:53 PM
We have a division that is still on Word97. They have several products that require specific styles. These styles are contained in Word templates (something.dot). The currently load the template with the styles they need, and produce a number of documents. When they need to switch styles they load another template. They styles from the first template are removed and the new styles become available. The styles need to remain available for every document until the next template is loaded.

Thanks for your help

GTO
10-25-2008, 01:16 AM
I don't believe you mentioned what version you're writing in, but I pulled this from Word 2003 Help. By memory, Word 2000 Help also includes most conversion information.

In Help, try keyword "WordBasic", and one of the topics should be:
Visual Basic Equivalents for WordBasic Commands
====================================================

From 2003 Help, WordBasic.FormatStyleGallery:


Copies styles from the specified template to a document.

expression.CopyStylesFromTemplate(Template)

expression Required. An expression that returns a Document object.

Template Required String. The template file name.

Remarks

When styles are copied from a template to a document, like-named styles in the
document are redefined to match the style descriptions in the template. Unique
styles from the template are copied to the document. Unique styles in the
document remain intact.

Example

This example copies the styles from the active document's template to the document.

ActiveDocument.CopyStylesFromTemplate _
Template:=ActiveDocument.AttachedTemplate.FullName

This example copies the styles from the Sales96.dot template to Sales.doc.

Documents("Sales.doc").CopyStylesFromTemplate _
Template:="C:\MSOffice\Templates\Sales96.dot"
===========================================================

Hope this helps,

Mark

fumei
10-27-2008, 09:25 AM
When you say "load" styles, do you mean by loading an add-in, a global template? That is the normal (and best) way to do that.

Or are you using different styles from different templates?

If you are loading the templates, as a global, an add-in, then you can easily do that with VBA. The styles in the template become available. When you want, you can either make them unavailable (but with the add-in still available); or make them unavailable and delete the add-in completely.

DavidFMayer
11-06-2008, 10:54 AM
I'm trying to replicate a word basic macro in VBA. Does anyone know what would be the equivalent to (WordBasic.FormatStyleGallery Template:="Normal").

Here is how.

First, add the following module into your system:

Option Explicit
Public WordBasicObject As Object

Public Sub WordBasicInit()
Dim TestApp As Object ' Test application to see if Word is running
Dim TestString As String ' test string
On Error GoTo -1: On Error Resume Next ' permit to drop through if CleanString fails.
TestString = WordBasicObject.WordBasic.CleanString("0")
On Error GoTo -1: On Error GoTo 0 ' reset error checking to normal
If WordBasicObject Is Nothing Or TestString = "" Then
' if WordBasicObject has not been initialized
On Error GoTo -1: On Error Resume Next ' permit to drop through if GetObject fails.
Set TestApp = GetObject(, "Word.Application")
' Try to find a Word application running
On Error GoTo -1: On Error GoTo 0 ' reset error checking to normal
If TestApp Is Nothing Then ' if Word is not running
Set WordBasicObject = CreateObject("Word.Application")
' set up new Word object and start process
Else ' if Word IS running
Set WordBasicObject = TestApp ' use existing Word object
End If
End If
End Sub

Next: Call the function at the top of any module that uses WordBasic functions thusly:

Call WordBasicInit

Finally, simply refer to the usual WordBasic functions as shown above in this line fully qualified as shown:

TestString = WordBasicObject.WordBasic.CleanString("0")

ALL of WordBasic is now available including:

WordBasicObject.WordBasic.Filenameinfo$(FileNameText, 1)
WordBasicObject.WordBasic.SortArray
WordBasicObject.WordBasic.FileName$()
WordBasicObject.WordBasic.Files$()

Stuff that explicitly refers to the Word buffer don't work, since there is no Word buffer.

I hope that this helps.

David