Microsoft KB Archive/105683: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 37: | Line 37: | ||
<pre class="CODESAMP">Dim WordObj As Object | <pre class="CODESAMP">Dim WordObj As Object | ||
Dim worddate As String | Dim worddate As String | ||
Set WordObj = CreateObject( | Set WordObj = CreateObject("Word.Basic") | ||
worddate = WordObj.[Date$]() | worddate = WordObj.[Date$]() | ||
MsgBox worddate </pre> | MsgBox worddate </pre> | ||
If you omit the square brackets that surround | If you omit the square brackets that surround "Date$", Visual Basic will post the following error message: | ||
<blockquote><div class="ERRORMESSAGE"> | <blockquote><div class="ERRORMESSAGE"> | ||
Line 51: | Line 51: | ||
The following WordBasic instruction shows the GetBookmark$() function as it might appear in a WordBasic macro: | The following WordBasic instruction shows the GetBookmark$() function as it might appear in a WordBasic macro: | ||
<pre class="CODESAMP"> mark$ = GetBookmark$( | <pre class="CODESAMP"> mark$ = GetBookmark$("Address") </pre> | ||
In Visual Basic, the same instruction would be specified as follows: | In Visual Basic, the same instruction would be specified as follows: | ||
<pre class="CODESAMP"> mark$ = WordObj.[GetBookmark$]( | <pre class="CODESAMP"> mark$ = WordObj.[GetBookmark$]("Address") </pre> | ||
The following Visual Basic procedure opens the Word document TEST.DOC, and then uses the WordBasic GetBookmark$() function to return the text of the | The following Visual Basic procedure opens the Word document TEST.DOC, and then uses the WordBasic GetBookmark$() function to return the text of the "Address" bookmark in a message box: | ||
<pre class="CODESAMP">Sub Command1_Click () | <pre class="CODESAMP">Sub Command1_Click () | ||
Dim WordObj As Object | Dim WordObj As Object | ||
Dim Mark As String | Dim Mark As String | ||
Set WordObj = CreateObject( | Set WordObj = CreateObject("Word.Basic") | ||
WordObj.FileOpen | WordObj.FileOpen "D:\WinWord6\Test.doc" | ||
Mark = WordObj.[GetBookmark$]( | Mark = WordObj.[GetBookmark$]("Address") | ||
MsgBox Mark | MsgBox Mark | ||
End Sub </pre> | End Sub </pre> | ||
== More Information == | == More Information == | ||
Visual Basic 4.x does not require the square backets | Visual Basic 4.x does not require the square backets "[ ]". They can however be used, as with VB3, without modification. | ||
Additional query words: 6.0 ole automation word basic word6 word7 7.0 word95 object visual dollar sign brackets function return winword | Additional query words: 6.0 ole automation word basic word6 word7 7.0 word95 object visual dollar sign brackets function return winword |
Latest revision as of 08:53, 20 July 2020
OLE Automation: Using Functions That Return Strings |
Q105683
The information in this article applies to:
- Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
- Microsoft Word for Windows, version 7.0
SUMMARY
When you use Microsoft WordBasic functions in Visual Basic, keywords that return strings--that is, keywords that end in a dollar sign ($)-- must be enclosed in square brackets or an error message will occur.
Example 1
The following WordBasic instruction returns the current date:
a$ = Date$()
In Visual Basic, the same instruction is specified as follows:
worddate = WordObj.[Date$]()
The following Visual Basic example uses Word's Date$() function to post the current date in a message box:
Dim WordObj As Object Dim worddate As String Set WordObj = CreateObject("Word.Basic") worddate = WordObj.[Date$]() MsgBox worddate
If you omit the square brackets that surround "Date$", Visual Basic will post the following error message:
Identifier can't end with type-declaration character
Example 2
The following WordBasic instruction shows the GetBookmark$() function as it might appear in a WordBasic macro:
mark$ = GetBookmark$("Address")
In Visual Basic, the same instruction would be specified as follows:
mark$ = WordObj.[GetBookmark$]("Address")
The following Visual Basic procedure opens the Word document TEST.DOC, and then uses the WordBasic GetBookmark$() function to return the text of the "Address" bookmark in a message box:
Sub Command1_Click () Dim WordObj As Object Dim Mark As String Set WordObj = CreateObject("Word.Basic") WordObj.FileOpen "D:\WinWord6\Test.doc" Mark = WordObj.[GetBookmark$]("Address") MsgBox Mark End Sub
More Information
Visual Basic 4.x does not require the square backets "[ ]". They can however be used, as with VB3, without modification.
Additional query words: 6.0 ole automation word basic word6 word7 7.0 word95 object visual dollar sign brackets function return winword
Keywords : kbole
Issue type :
Technology :
Last Reviewed: November 4, 2000 |