Developer FAQs - SystemWelcome to Baarns Publishing's Word Developers FAQ section. If you develop in Microsoft Word using Word Basic, these tips are for you. Feel free to copy any of the code you find here and use in your development projects. |
| |
|
Word 7.0 via OLE automation is slow! How do I speed it up?
Keywords: OLE Speed Performance
Posted June 20, 1996
There have been benchmark test that show OLE Automation statements from VB4 32-bit to Word 7.0 being up to 10 time slower than VB3 to Word 6.0. There are a number of steps that can be taken to improve the performance.
Dim wrdBas as Word.WordBasic
Set wrdBas = CreateObject("Word.Basic")
wrdBas.Insert "Baarns Consulting Group, Inc."
When possible use WordBasic macros or solutions from within Word. For example use Autotext entries to store frequently used text strings. Besides the fact that Autotext entries exist within Word, Autotext entries preserve formatting and bookmarks. This can eliminate the need of applying formatting via code. Note: The absolute slowest and worse possible scenario is VB3 to Word 7. This coupling is 22 time slower than VB3 to Word 6.
Why don't my Windows API calls work in Word 7?
Keywords: WinAPI, Win32API
Posted June 20, 1996
Word for Windows 7 (frequently called Word95) and Word for Windows NT 6.0 are both 32 bit products. 32 bit is the addressing scheme the applications use to communicate with the operating system (very simplified). The addressing scheme is how information is passed back and forth between dynamic load libraries (DLL). Because of the address difference it is not possible for a 32 bit application to load and use16-bit DLL (there are exceptions to this but Word is not one of them).
If you have 16 bit DLL's or WLL's written for Word they will need to be recompiled as 32-bit libraries. If this is not possible you can continue to run Word 6.0 on Windows 95 or NT.
Use this link for a more detailed answer.
The more common problem is trying to find the Windows API calls for 32 bit. Microsoft Visual Basic User Ed team has compiled a text file with all of the Win32API declares for Visual Basic (Win32API.txt). Use this link to download this file.
For more information on converting Visual Basic API declarations to WordBasic declarations refer to the Microsoft article "Calling Windows® API Functions from WordBasic".
Via OLE Automation, how do you bring Word 6.0 up hidden?
Keywords: OLE Word 6.0
Posted June 20, 1996
Word has 3 OLE Automation Program Identifiers (ProgID). These are Word.Basic, Word.Document and Word.Picture. In Word 6.0 if you use Word.Basic for your ProgID Word will launch in a visible state with no document (assuming that Word was not already running). If you use Word.Document for your ProjID Word 6.0 will launch in an hidden state.
By referencing the WordBasic object off of the Application object you can still get a reference to the WordBasic object from the Word.Document object.
'Visual Basic Code
Sub CallWord()
Dim wrdBas as Object
Dim wrdDoc as Object
Set wrdDoc = CreateObject("Word.Document")
'Word is in a hidden state now.
Set wrdBas = wrdDoc.Application.WordBasic
wrdBas.FileNewDefault
wrdBas.Style "Caption"
wrdBas.Insert "Baarns Consulting Group, Inc."
wrdBas.Insert "http://www.baarns.com"
'Make Word visible now.
WrdBas.AppShow
End Sub
Note: in Word 7.0 the Word.Basic ProgID lauches Word in a hidden state. Therefore this workaround is no longer necessary.
How do I retrieve the User and Computer Name on Windows 95?
Keywords: Win95 Network
Posted June 20, 1996
This information is stored in the windows registry. By using the GetPrivateProfileString$() function and knowing the proper keys we can extract this information.
Sub MAIN HKEY_LOGON$ = "HKEY_LOCAL_MACHINE\Network\Logon" HKEY_COMPUTER$ = "HKEY_LOCAL_MACHINE\System\CurrentControlSet" + \ "\Control\ComputerName\ComputerName" szUser$ = GetPrivateProfileString$(HKEY_LOGON$, "UserName", "") szComputer$ = GetPrivateProfileString$(HKEY_COMPUTER$, \ "ComputerName", "") MsgBox "User is " + szUser$ + Chr$(13) + "on " + szComputer$ End Sub
How do I detect what operating system is running?
Keywords: Operating System
Posted April 5, 1996
The WordBasic AppInfo$(1) function returns the operating system that is running. If Word 6.0 is running on NT this function will return 'Win 3.1'. This is because Word 6.0 is running in an sub-system on NT, which thinks it is Windows 3.1.
Function GetOS$
OSInfo$ = AppInfo$(1)
If InStr(OSInfo$, "NT") Then
GetOS$ = "NT"
ElseIf InStr(OSInfo$, "95") Then
GetOS$ = "Win95"
ElseIf InStr(OSInfo$, "Windows") Then
GetOS$ = "Win3.1"
ElseIf InStr(OSInfo$, "Mac") Then
GetOS$ = "Mac"
Else
GetOS$ = OSInfo$'Unknown pass it on.
End If
End Function
How do I find the path of an Microsoft Office application?
Keywords: MS Office App Path
Posted April 5, 1996
All of the Microsoft Office application are OLE servers. Because of this they install specific information into the registry. Such as the path to the server. The GetServerPath$() function extracts the path of a specified class ID from the registry. The class ID is the unique string that identifies the application, such as Word.Application or Excel.Application.
WordBasic provides the GetPrivateProfileString$ function to read from either the registry or an INI file (under Windows 95 or Windows NT). The below function is an example of using GetPrivateProfileString to extract information from the registry.
Note: Word for Windows is not OLE automation client. That does not stop you from using information provided in the registry for OLE automation clients.
Sub MAIN
MsgBox GetServerPath$("Word.Basic")
MsgBox GetServerPath$("Excel.Application")
MsgBox GetServerPath$("Access.Application")
MsgBox GetServerPath$("Dao.DBEngine")
MsgBox GetServerPath$("MS_Clipart_Gallery.2")
MsgBox GetServerPath$("Office.Binder")
MsgBox GetServerPath$("Paint.Picture")
MsgBox GetServerPath$("PowerPoint.Application")
End Sub
'***********************************************************************
' Function GetServerPath()
'
' Arguments: pstrServer$; Class ID of server.
' Purpose: Return the full path of server.
' Returns: Success; full path to server. Failure; empty string.
'
' Author: Steven (Smitch) Mitchell
' Date: 4/1/96
' Copyright Baarns Consulting Group, Inc. 1996
'***********************************************************************
Function GetServerPath$(pstrServer$)
'
'Need to find the CLSID of the server first.
'
Section$ = "HKEY_CLASSES_ROOT\" + pstrServer$ + "\CLSID"
sCLSID$ = GetPrivateProfileString$(Section$, "", "")
'
'If sCLSID$ is empty then application is not installed (correctly).
'
If sCLSID$ = "" Then Goto Exit_GetServerPath
'
'Now need find the LocalServer path.
'
Section$ = "HKEY_CLASSES_ROOT\CLSID\" + sCLSID$
Section16$ = Section$ + "\LocalServer"
Section32$ = Section$ + "\LocalServer32"
sLocalServer$ = GetPrivateProfileString$(Section32$, "", "")
'
'If empty check the 16 bit server key.
'
If sLocalServer$ = "" Then
sLocalServer$ = GetPrivateProfileString$(Section16$, "", "")
If sLocalServer$ = "" Then
sLocalServer$ = GetPrivateProfileString$(Section$ + \
"\InprocServer32", "", "")
End If
End If
'
'Remove the /automation switch if it exist.
'
iOffset = InStr(LCase$(sLocalServer$), "/automation")
If iOffset Then
sLocalServer$ = Left$(sLocalServer$, iOffset - 2)
End If
'
'Check to see if the path exist.
'
On Error Resume Next
sExist$ = LCase$(Files$(sLocalServer$))
'Use InStr because Files$ might put "" around the long file name.
If InStr(sExist$, LCase$(sLocalServer$)) = 0 Then
'Set this to an empty string, a failure result.
sLocalServer$ = ""
End If
On Error Goto 0
GetServerPath$ = sLocalServer$
Exit_GetServerPath:
End Function
How do I find where users templates are stored on a system?
Keywords: Users Template Stored
Posted April 5, 1996
All of the paths that Word for Windows uses are stored in either the registry or WINWORD6.INI. Depending on version of Word for Windows and operating system. Extracting this information can be platform independent by using the built in commands of Word. Below is a function that demonstrates extracting the User Templates path that is also platform independent. It can be easily modified for the other settings.
For more information on the other settings look at the WordBasic help topic on ToolsOptionsFileLocations.
Sub MAIN
'demonstrates the function.
MsgBox GetUserDotPath$
End Sub
'***********************************************************************
' Function GetUserDotPath&()
'
' Arguments: None
' Purpose: Return the path of User Templates.
' Returns: Success; Path to User-Dot-Path. Failure; empty string.
'
' Author: Steven (Smitch) Mitchell
' Date: 4/1/96
' Copyright Baarns Consulting Group, Inc. 1996
'***********************************************************************
Function GetUserDotPath$
Dim dlgTOFL As ToolsOptionsFileLocations
dlgTOFL.Path = "USER-DOT-PATH"
GetCurValues dlgTOFL
sUserDotPath$ = dlgTOFL.Setting
If sUserDotPath$ = "" Then
Goto Exit_GetUserDotPath 'Failure.
End If
'
'Test to see that directory actually exist.
'
On Error Goto Exit_GetUserDotPath
sCurDir$ = Files$(".") 'Store current directory setting.
ChDir sUserDotPath$ 'Go to the suggested directory.
sExistDir$ = Files$(".") 'Verify that the directory was changed.
If InStr(sExistDir$, sUserDotPath$) = 0 Then
sUserDotPath$ = ""
End If
'Restore the directory to the previous directory.
ChDir sCurDir$
GetUserDotPath$ = sUserDotPath$
Exit_GetUserDotPath:
End Function
Back to the FAQ Table of Contents
A mainframe: The biggest PC peripheral available. |
Copyright© 1996-1999, Baarns Consulting Group, Inc. - All rights reserved. |