Wednesday, August 5, 2009

MacroLabs | Open another file using macro

If you want to open another file or your macro wants to process another file, use these codes below to open the 'Open Dialog Box'. THe file will open after you select it.

Private Sub Document_Open()
'This macro will open a new file using the 'Open Dialog Box'

Dim defDir As String
'variable used which refers to Default Directory you want to set

defDir = "C:\fts"
'you can specify your own directory here

With Application.Dialogs(wdDialogFileOpen)
Options.DefaultFilePath(Path:=wdDocumentsPath) = defDir

If .Display Then
Documents.Open FileName:=.Name
End If

End With
'you can write other codes here

End Sub



Note: Basically the default file type you can open is a ".doc" file.
You can set and filter the file types you want to open using another property.

No comments:

Post a Comment