+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    01-13-2009
    Location
    Berkley Heights, NJ
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question Macro that forces user to save file on open

    I need to crate a macro that will force the user to save the file as a different name when they open the file
    I have this code and it works. I just need to have it run when the file is opened. Is there an on open function that I can add to make it do this?

    Sub FS()
    'fileSaveName = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xls), *.xls")
    fileSavename = Application.GetSaveAsFilename( _
    fileFilter:="Excel Files (*.xls), *.xls")
    'If user specified file name, perform Save and display msgbox

    If fileSavename <> False Then
    pointPos = InStrRev(fileSavename, ".")
    fileSavename = Left(fileSavename, pointPos - 1) & Mid(fileSavename, pointPos)
    ActiveWorkbook.SaveAs Filename:=fileSavename, FileFormat:=xlNormal

    MsgBox "Save As " & fileSavename
    End If

    End Sub

    Thanks a bunch.

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    797

    Re: Macro that forces user to save file on open

    you can use the open procudure. " put this is ths workbook section"

    Code:
    Private Sub Workbook_Open()
    
    End Sub
    Aternalty to force the user to save to a directory of your choosing can be done like.
    Code:
    Sub just4you()
    Dim strName As String
    
    strName = InputBox(Prompt:="You name please.", _
              Title:="ENTER YOUR NAME", Default:="Your Name here")
    If strName = "" Then strName = "choose a name"
    
    ActiveWorkbook.SaveAs Filename:= _
            "C:\Documents and Settings\1 1\Desktop\" & strName, FileFormat:= _
            xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
    
    End Sub
    hope that helps.

  3. #3
    Registered User
    Join Date
    08-16-2009
    Location
    Fort Smith, AR
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Macro that forces user to save file on open

    So if you paste your code in the workbook_Open module it will run everytime the book is opened.

    This is found in a section above the macro modules called 'ThisWorkbook' From there paste this in and it should work fine.


    Code:
    Private Sub Workbook_Open()
        'fileSaveName = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xls), *.xls")
        fileSavename = Application.GetSaveAsFilename( _
        fileFilter:="Excel Files (*.xls), *.xls")
        'If user specified file name, perform Save and display msgbox
        
        If fileSavename <> False Then
        pointPos = InStrRev(fileSavename, ".")
        fileSavename = Left(fileSavename, pointPos - 1) & Mid(fileSavename, pointPos)
        ActiveWorkbook.SaveAs Filename:=fileSavename, FileFormat:=xlNormal
        
        MsgBox "Save As " & fileSavename
        End If
    End Sub

  4. #4
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,136

    Re: Macro that forces user to save file on open

    dmars, please take a few minutes to read the forum rules, and then edit your post to add code tags.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

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.2.0