Open related procedures in class Document (Word VBA)

This page presents procedures from class Document related to the theme Open: CompatibilityMode, OpenEncoding, ReadOnly, ReadOnlyRecommended, SetCompatibilityMode, Documents.CanCheckOut, Documents.CheckOut, Documents.Open and Documents.OpenNoRepairDialog

CompatibilityMode

Returns a Long that specifies the compatibility mode that Word uses when opening the document.

When you open a document in Word that was created in a previous version of Word, Compatibility Mode is turned on. Compatibility Mode ensures that no new or enhanced features in Word are available while working with a document, so that people who edit the document using previous versions of Word will have full editing capabilities.

Sub InsertCheckbox()
       
    If (Application.Version = ActiveDocument.CompatibilityMode) Then
          Selection.Range.ContentControls.Add (wdContentControlCheckBox)
    End If    
End Sub

OpenEncoding

Returns the encoding used to open the specified document.

If ActiveDocument.OpenEncoding = msoEncodingUTF7 Then 
 MsgBox "This is a UTF7-encoded text file!" 
Else 
 MsgBox "This is not a UTF7-encoded text file!" 
End If

ReadOnly

True if changes to the document cannot be saved to the original document.

If ActiveDocument.ReadOnly = False Then ActiveDocument.Save

ReadOnlyRecommended

True if Microsoft Word displays a message box whenever a user opens the document, suggesting that it be opened as read-only.

ActiveDocument.ReadOnlyRecommended = True

SetCompatibilityMode

Syntax : expression.SetCompatibilityMode (Mode)

Documents.CanCheckOut

True if Microsoft Word can check out a specified document from a server.

To take advantage of the collaboration features built into Word, documents must be stored on a Microsoft SharePoint Portal Server.

Syntax : expression.CanCheckOut (FileName)

FileName: The server path and name of the document.

Sub CheckInOut(docCheckOut As String) 
 If Documents.CanCheckOut(docCheckOut) = True Then 
 Documents.CheckOut docCheckOut 
 Else 
 MsgBox "You are unable to check out this document at this time." 
 End If 
End Sub

Documents.CheckOut

Copies a specified document from a server to a local computer for editing.

To take advantage of the collaboration features built into Word, documents must be stored on a Microsoft SharePoint Portal Server.

Syntax : expression.CheckOut (FileName)

FileName: The name of the file to check out.

Sub CheckInOut(docCheckOut As String) 
 If Documents.CanCheckOut(docCheckOut) = True Then 
 Documents.CheckOut docCheckOut 
 Else 
 MsgBox "You are unable to check out this document at this time." 
 End If 
End Sub

Documents.Open

Opens the specified document and adds it to the Documents collection. Returns a Document object.

Syntax : expression.Open (FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog, XMLTransform)

Sub OpenDoc() 
 Documents.Open FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True 
End Sub

Arguments

The following argument is required

FileName (String) - The name of the document (paths are accepted).

The following arguments are optional

ConfirmConversions (Boolean) - True to display the Convert File dialog box if the file isn't in Microsoft Word format.

ReadOnly (Boolean) - True to open the document as read-only. This argument doesn't override the read-only recommended setting on a saved document. For example, if a document has been saved with read-only recommended turned on, setting the ReadOnly argument to False will not cause the file to be opened as read/write.

AddToRecentFiles (Boolean) - True to add the file name to the list of recently used files at the bottom of the File menu.

PasswordDocument (String) - The password for opening the document.

PasswordTemplate (String) - The password for opening the template.

Revert (Boolean) - Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.

WritePasswordDocument (String) - The password for saving changes to the document.

WritePasswordTemplate (String) - The password for saving changes to the template.

Format (FileConverter) - The file converter to be used to open the document. Can be one of the WdOpenFormat constants. The default value is wdOpenFormatAuto. To specify an external file format, apply the OpenFormat property to a FileConverter object to determine the value to use with this argument.

Encoding (String) - The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document. Can be any valid MsoEncoding constant. For the list of valid MsoEncoding constants, see the Object Browser in the Visual Basic Editor. The default value is the system code page.

Visible (Boolean) - True if the document is opened in a visible window. The default value is True.

OpenAndRepair (Boolean) - True to repair the document to prevent document corruption.

DocumentDirection (WdDocumentDirection) - Indicates the horizontal flow of text in a document. The default value is wdLeftToRight.

Possible Values are wdLeftToRight - Left to right, wdRightToLeft - Right to left.

NoEncodingDialog (Boolean) - True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.

XMLTransform - String

Documents.OpenNoRepairDialog

Opens the specified document and adds it to the Documents collection.

Syntax : expression.OpenNoRepairDialog (FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog, XMLTransform)

Sub OpenDoc() 
 Documents.OpenNoRepairDialog FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True 
End Sub

Arguments

The following argument is required

FileName (String) - The name of the document (paths are accepted).

The following arguments are optional

ConfirmConversions (Boolean) - True to display the Convert File dialog box if the file is not in Microsoft Word format.

ReadOnly (Boolean) - True to open the document as read-only. This argument does not override the read-only recommended setting on a saved document. For example, if a document has been saved with read-only recommended turned on, setting the ReadOnly argument to False will not cause the file to be opened as read/write.

AddToRecentFiles (Boolean) - True to add the file name to the list of recently used files at the bottom of the File menu.

PasswordDocument (String) - The password for opening the document.

PasswordTemplate (String) - The password for opening the template.

Revert (Boolean) - Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.

WritePasswordDocument (String) - The password for saving changes to the document.

WritePasswordTemplate (String) - The password for saving changes to the template.

Format (WdOpenFormat) - The file converter to be used to open the document. Can be one of the WdOpenFormat constants. The default is wdOpenFormatAuto.

Here you can find possible values for WdOpenFormat.

Encoding (String) - The document encoding (code page or character set) to be used by Word when you view the saved document. Can be any valid MsoEncoding constant. For the list of valid MsoEncoding constants, see the Object Browser in the Visual Basic Editor. The default is the system code page.

Visible (Boolean) - True if the document is opened in a visible window. The default is True.

OpenAndRepair (Boolean) - True to repair the document to prevent document corruption.

DocumentDirection (WdDocumentDirection) - Indicates the horizontal flow of text in a document. Can be any valid WdDocumentDirection constant. The default is wdLeftToRight.

Possible Values are wdLeftToRight - Left to right, wdRightToLeft - Right to left.

NoEncodingDialog (Boolean) - True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default is False.

XMLTransform (String) - Specifies a transform to use.