-
Hi Killian, sorry, have been away for a few days. I have tried your code, I think I have almost got it, but I think there is something that I havent done properly with the SaveSetting function. Would you mind having a quick look? Here is the code that is saved in a standard module:
[VBA]
Option Explicit
Public strUserRole As String
Sub Workbook_Open()
DeleteMenu
BuildMenu
End Sub
Sub Workbook_BeforeClose(Cancel As Boolean)
DeleteMenu
End Sub
Sub BuildMenu()
Dim cb As CommandBarControl
With Application.CommandBars("Worksheet Menu Bar") bar
Set cb = .Controls.Add(msoControlPopup, Temporary:=True)
With cb
.Caption = "Save"
.OnAction = "FOI"
End With
End With
'initialze the global variable with the registry setting
strUserRole = GetSetting("FOI", "UserProfile", "Post", "Nothing")
If strUserRole = "Nothing" Then
SaveUserRole
End If
End Sub
Sub SaveUserRole()
'initialize the global variable user prompt
strUserRole = InputBox("Enter your Post", "Amend User", "<Post Title>")
'and save the setting
SaveSetting "FOI", "UserProfile", "Post", strUserRole
SubjectNameForm.Post.Value = strUserRole ' is this part required????
End Sub
Sub DeleteMenu()
Dim cb As CommandBarControl
For Each cb In Application.CommandBars("Worksheet Menu Bar").Controls
If cb.Caption = "Save" Then cb.Delete
Next
End Sub
Sub FOI()
If Application.Workbooks.Count > 0 Then ' i.e. MS Excell is open, but no workbooks open
Load SubjectNameForm
SubjectNameForm.Show
Else
MsgBox "Nothing to save"
End If
End Sub
[/VBA]
The userform (SubjectNameForm) displays a textbox (called Post) which is supposed to have the user post title in it: however, it only displays it once, which leads me to believe that I have written the savesetting function incorectly, or that I have written the getsetting function incorrectly.
There is also a button on the userform which prompts a input box if the user wishes to ammend his/her post title at a later date, see below:
[VBA] Private Sub AmmendAuthor_Click()
strUserRole = InputBox("Enter your Post", "Amend User", "<Post Title>")
'and save the setting
SaveSetting "FOI", "UserProfile", "Post", strUserRole
SubjectNameForm.Post.Value = strUserRole ' is this required??????
End Sub[/VBA]
PS I have been reading up on add-ins, they seem like the best way for my purposes, thank you for the tip.
Sam
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules