Results 1 to 7 of 7

Thread: check for fields filled out

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    Butler, PA
    Posts
    3

    check for fields filled out

    I have an Excel (ver. 2003) spreadsheet that needs certain fields populated before it can be saved or closed. I know I have to use the BeforeSave function, but I am unfamilar with it. I am also aware that macros need enabled and would like some help writing code that would lock the workbook and prompt the user to enable macros if they initially choose not to enable them. Thanks in advance for any help!!
    Mike Hart

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: check for fields filled out

    1) yes, use the BeforeSave event of ThisWorkbook
    2) you cant.. if the user chooses to disable macros, then you cant get around it by normal means. since they are disabling macros, no macro can run to lock and prompt

    you could write an Add-in or a macro workbook in XLStart
    workbooks in XLStart can run macros without users having to enable them

    If you do this, you will need to Grab the application on open of the workbook.. and watch the app events for Beforesave... then when it occurs.. check the workbook, see if its the "correct" one and not some other workbook. then check the fields.
    the user would need to add this workbook to their XLStart forlder for it to work.

    Add-in would work much the same way, but its a little harder to write and would require the user to "install" by registering the dll.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    Butler, PA
    Posts
    3

    Re: check for fields filled out

    Could I get some guidance on the code for the beforesave function?
    Mike Hart

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: check for fields filled out

    Start a new workbook...
    MENU: Window > Hide
    so you cant see the workbook

    now ALT+F11 to bring up the code window

    VB Code:
    1. Dim WithEvents XLS As Application
    2. Private Sub Workbook_Open()
    3.     Set XLS = Application
    4. End Sub
    5.  
    6.  
    7.  
    8. Private Sub XLS_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean)
    9.     MsgBox "You are about to save " & Wb.Name
    10. End Sub

    no use the wb object in the before save to test if its the right workbook...
    then you can run thru and look for the fields...

    now save this in your XLStart Folder...
    C:\.....\OFFICE11\XLSTART\

    now close excel.

    open the other workbook.. and trigger the code by saving it,,,
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Location
    Butler, PA
    Posts
    3

    Re: check for fields filled out

    Thank you.
    Mike Hart

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: check for fields filled out

    you are welcome.

    if this is resolved.. please click thread tools > mark thread resolved. (its about your first post)

    Thanks!! and
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: check for fields filled out

    if you save the workbook locked and passworded, then use the macro to unlock it, lock again on close.

    no macro, no unlock

    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width