Further to my earlier message, this class can be added to give a
reliable 'read-only' tag in the title bar when using the full path in
title bar code.[Class ToggleReadOnlyEvents]
Option Explicit
Private WithEvents togReadOnlyButton As Office.CommandBarButton
Private Sub Class_Initialize()
' Not sure if this ID is stable. Could use the name instead.
Set togReadOnlyButton = CommandBars.FindControl(ID:=456)
End Sub
Private Sub Class_Terminate()
Set togReadOnlyButton = Nothing
End Sub
Private Sub togReadOnlyButton_Click( _
ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
Dim Wb As Workbook
Set Wb = ActiveWorkbook
If Wb.ReadOnly = True Then
If GetAttr(Wb.FullName) And vbReadOnly Then
MsgBox quot;'quot; amp; Wb.Name amp; quot;' is read-only.quot; _
amp; quot; To save a copy, click OK, then give thequot; _
amp; quot; workbook a new name in the Save As dialog box.quot;, _
vbExclamation, quot;Microsoft Excelquot;
Else
Wb.ChangeFileAccess xlReadWrite
End If
Else
Wb.ChangeFileAccess xlReadOnly
End If
showFullName Wb
CancelDefault = True
End Sub
Private Sub showFullName(Wb As Workbook)
Dim caption As String
On Error Resume Next
caption = Wb.FullName
If Wb.ReadOnly Then
caption = caption amp; quot; [Read-Only]quot;
End If
Wb.Windows(1).caption = caption
End SubThere seems to be a problem with putting the path in the title bar
using the workbook open event. The problem is, if you have code like
this:
Set a_workbook = Application.Workbooks.Open(quot;abc.xlsquot;, 0, True)
And abc.xls has a VBA reference to another workbook. Then a_workbook
will (or at least it will with my workbook) be set to the referenced
workbook, not abc.xls. Which is not the behaviour if the workbook open
event is not used.
- Sep 29 Fri 2006 20:09
Full path in title bar
close
全站熱搜
留言列表
發表留言