Egna filer i åtgärdsfönster
I Word 2003 visas åtgärdsfönstret Komma igång och Nytt dokument vid start. I åtgärdsfönstret Nytt dokument visas länkar till de dokument du senast använt samt länkar till de mallar du senast använd.
Det går alldeles utmärkt att lägga till egna länkar till dessa åtgärdsfönster för att ha snabb åtkomst till sina favoritdokument.
Skapa en ny VBA-modul och lägg in följande kod:
Private Sub NewDocumentAdd( _
Filename As String, _
Optional FileSection As MsoFileNewSection = msoOpenDocument, _
Optional Displayname As String, _
Optional Action As MsoFileNewAction = msoCreateNewFile, _
Optional Refresh As Boolean = True)
'Prevent duplicate entries
NewDocumentRemove Filename, FileSection, Displayname, Action, False
'Add it
With Application
.NewDocument.Add Filename, FileSection, Displayname, Action
If Refresh Then
With .CommandBars("Task Pane")
.Visible = False
.Visible = True
End With
End If
End With
End Sub
Private Sub NewDocumentRemove( _
Filename As String, _
Optional FileSection As MsoFileNewSection = msoOpenDocument, _
Optional Displayname As String, _
Optional Action As MsoFileNewAction = msoEditFile, _
Optional Refresh As Boolean = True)
Dim FileStart As Long
With Application
'Create display name
If Len(Displayname) = 0 Then
FileStart = InStrRev(Filename, .PathSeparator)
If FileStart = 0 Then
Displayname = Filename
Else
Displayname = Mid$(Filename, FileStart + 1)
End If
End If
'Remove
.NewDocument.Remove Filename, FileSection, Displayname, Action
If Refresh Then
With .CommandBars("Task Pane")
.Visible = False
.Visible = True
End With
End If
End With
End Sub
För att lägga till nya dokument anropar du sedan dessa makron så här:
NewDocumentAdd "C:\Temp\SillyFilename.doc", msoBottomSection, _
"Mall i BottomSection", , False
Den andra parameter styr på vilken plats dokumentet ska hamna. Du kan välja mellan dessa konstanter:
- msoBottomSection
- msoNew
- msoNewfromExistingFile
- msoNewfromTemplate
- msoOpenDocument
För att ta bort dokument gör du så här:
NewDocumentRemove "C:\Temp\SillyFilename.doc", msoBottomSection, "Mall i BottomSection", , False
Mvh // Johan