Documents


Document File Name

This line will return the filename of the active document.

Application.ActiveDocument.Name = Document1.doc 
ActiveDocument.Name = Document1.doc
Application.Documents.Item(2).Name

If the active document has not been saved yet then this returns the filename with no extension

ActiveDocument.Name = Document2 

You can check if a document has been saved or not by checking if the following are the same

If (ActiveDocument.Name = ActiveDocument.FullName) Then 
'document has not been saved yet
End If

Document Folder

This line returns the folder path of where the document is saved

Application.ActiveDocument.Path 
ActiveDocument.Path

If the active document has not been saved then this is blank ???


Document Folder and FileName

This returns the full folder path and the filename

ActiveDocument.FullName 

This line is equivalent to the following

ActiveDocument.Path & ActiveDocument.PathSeparator & ActiveDocument.Name 

Looping Through Open Documents


Dim icount As Integer 
For icount = 1 To Application.Documents.Count
   If (Application.Documents(icount).Name - "Document1") Then
   End If
Next icount

A lot of windows related properties are actually properties of the Pane object which is associated with the window.
This line will create an error if there is no document currently open

If (Application.Documents.Count > 1) Then 
   sName = ActiveDocument.Name
End If

Set objRange = ActiveDocument.Content 
Set objRange = ActiveDocument.Range


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext