+ Reply to Thread
Results 1 to 2 of 2

Header Macro with a list box

Hybrid View

  1. #1
    Registered User
    Join Date
    07-15-2007
    Posts
    1

    Question Header Macro with a list box

    Hi friends,

    Im looking for the code to develop a macro which will give me a pop-up of a list box before Save As option. The list box will have the types of header for data classification. Once I select a type of header, the same will be set for that particular excel file.
    eg:
    1) I select the Save as option,
    2) List box pops up
    3) From the list box, I select Internal Confidential
    4) Header is set as "Internal Confidential"
    5) The Save as option widow pops up

    Why I need this....

    I have several types of header...so every time I have to change the existing header/ add a new header

    Thanks

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I would create a userForm with the Options that you want. then in the Workbook_BeforeSave
    place this code

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
        Cancel = True
        UserForm1.Show
    End Sub
    The userform would have Listbox containing your choices. Use the Listbox click event to set the header

    Option Explicit
    
    Private Sub ListBox1_Click()
        Dim sHeader As String
        With Me.ListBox1
            If .ListIndex > -1 Then
                Select Case .ListIndex
                    Case 0: sHeader = "Confidebtial"
                    Case 1: sHeader = "Private"
                    Case Else    'allow close without setting header
                        Unload Me
                        ThisWorkbook.Save True
                End Select
            End If
        End With
        ActiveSheet.PageSetup.CenterHeader = sHeader
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1